navigation_server_3d.cpp 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  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. navigation_debug_dirty = true;
  232. call_deferred("_emit_navigation_debug_changed_signal");
  233. avoidance_debug_dirty = true;
  234. call_deferred("_emit_avoidance_debug_changed_signal");
  235. }
  236. #endif // DEBUG_ENABLED
  237. }
  238. bool NavigationServer3D::get_debug_enabled() const {
  239. return debug_enabled;
  240. }
  241. #ifdef DEBUG_ENABLED
  242. void NavigationServer3D::_emit_navigation_debug_changed_signal() {
  243. if (navigation_debug_dirty) {
  244. navigation_debug_dirty = false;
  245. emit_signal(SNAME("navigation_debug_changed"));
  246. }
  247. }
  248. void NavigationServer3D::_emit_avoidance_debug_changed_signal() {
  249. if (avoidance_debug_dirty) {
  250. avoidance_debug_dirty = false;
  251. emit_signal(SNAME("avoidance_debug_changed"));
  252. }
  253. }
  254. #endif // DEBUG_ENABLED
  255. #ifdef DEBUG_ENABLED
  256. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_geometry_face_material() {
  257. if (debug_navigation_geometry_face_material.is_valid()) {
  258. return debug_navigation_geometry_face_material;
  259. }
  260. bool enabled_geometry_face_random_color = get_debug_navigation_enable_geometry_face_random_color();
  261. Ref<StandardMaterial3D> face_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  262. face_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  263. face_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  264. face_material->set_albedo(get_debug_navigation_geometry_face_color());
  265. face_material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
  266. face_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  267. if (enabled_geometry_face_random_color) {
  268. face_material->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true);
  269. face_material->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
  270. }
  271. debug_navigation_geometry_face_material = face_material;
  272. return debug_navigation_geometry_face_material;
  273. }
  274. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_geometry_edge_material() {
  275. if (debug_navigation_geometry_edge_material.is_valid()) {
  276. return debug_navigation_geometry_edge_material;
  277. }
  278. bool enabled_edge_lines_xray = get_debug_navigation_enable_edge_lines_xray();
  279. Ref<StandardMaterial3D> line_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  280. line_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  281. line_material->set_albedo(get_debug_navigation_geometry_edge_color());
  282. line_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  283. if (enabled_edge_lines_xray) {
  284. line_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  285. }
  286. debug_navigation_geometry_edge_material = line_material;
  287. return debug_navigation_geometry_edge_material;
  288. }
  289. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_geometry_face_disabled_material() {
  290. if (debug_navigation_geometry_face_disabled_material.is_valid()) {
  291. return debug_navigation_geometry_face_disabled_material;
  292. }
  293. Ref<StandardMaterial3D> face_disabled_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  294. face_disabled_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  295. face_disabled_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  296. face_disabled_material->set_albedo(get_debug_navigation_geometry_face_disabled_color());
  297. face_disabled_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  298. debug_navigation_geometry_face_disabled_material = face_disabled_material;
  299. return debug_navigation_geometry_face_disabled_material;
  300. }
  301. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_geometry_edge_disabled_material() {
  302. if (debug_navigation_geometry_edge_disabled_material.is_valid()) {
  303. return debug_navigation_geometry_edge_disabled_material;
  304. }
  305. bool enabled_edge_lines_xray = get_debug_navigation_enable_edge_lines_xray();
  306. Ref<StandardMaterial3D> line_disabled_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  307. line_disabled_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  308. line_disabled_material->set_albedo(get_debug_navigation_geometry_edge_disabled_color());
  309. line_disabled_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  310. if (enabled_edge_lines_xray) {
  311. line_disabled_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  312. }
  313. debug_navigation_geometry_edge_disabled_material = line_disabled_material;
  314. return debug_navigation_geometry_edge_disabled_material;
  315. }
  316. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_edge_connections_material() {
  317. if (debug_navigation_edge_connections_material.is_valid()) {
  318. return debug_navigation_edge_connections_material;
  319. }
  320. bool enabled_edge_connections_xray = get_debug_navigation_enable_edge_connections_xray();
  321. Ref<StandardMaterial3D> edge_connections_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  322. edge_connections_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  323. edge_connections_material->set_albedo(get_debug_navigation_edge_connection_color());
  324. edge_connections_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  325. if (enabled_edge_connections_xray) {
  326. edge_connections_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  327. }
  328. edge_connections_material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);
  329. debug_navigation_edge_connections_material = edge_connections_material;
  330. return debug_navigation_edge_connections_material;
  331. }
  332. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_link_connections_material() {
  333. if (debug_navigation_link_connections_material.is_valid()) {
  334. return debug_navigation_link_connections_material;
  335. }
  336. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  337. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  338. material->set_albedo(debug_navigation_link_connection_color);
  339. material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  340. if (debug_navigation_enable_link_connections_xray) {
  341. material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  342. }
  343. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);
  344. debug_navigation_link_connections_material = material;
  345. return debug_navigation_link_connections_material;
  346. }
  347. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_link_connections_disabled_material() {
  348. if (debug_navigation_link_connections_disabled_material.is_valid()) {
  349. return debug_navigation_link_connections_disabled_material;
  350. }
  351. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  352. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  353. material->set_albedo(debug_navigation_link_connection_disabled_color);
  354. material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  355. if (debug_navigation_enable_link_connections_xray) {
  356. material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  357. }
  358. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);
  359. debug_navigation_link_connections_disabled_material = material;
  360. return debug_navigation_link_connections_disabled_material;
  361. }
  362. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_agent_path_line_material() {
  363. if (debug_navigation_agent_path_line_material.is_valid()) {
  364. return debug_navigation_agent_path_line_material;
  365. }
  366. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  367. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  368. material->set_albedo(debug_navigation_agent_path_color);
  369. material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  370. if (debug_navigation_enable_agent_paths_xray) {
  371. material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  372. }
  373. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);
  374. debug_navigation_agent_path_line_material = material;
  375. return debug_navigation_agent_path_line_material;
  376. }
  377. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_agent_path_point_material() {
  378. if (debug_navigation_agent_path_point_material.is_valid()) {
  379. return debug_navigation_agent_path_point_material;
  380. }
  381. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  382. material->set_albedo(debug_navigation_agent_path_color);
  383. material->set_flag(StandardMaterial3D::FLAG_USE_POINT_SIZE, true);
  384. material->set_point_size(debug_navigation_agent_path_point_size);
  385. material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  386. if (debug_navigation_enable_agent_paths_xray) {
  387. material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  388. }
  389. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);
  390. debug_navigation_agent_path_point_material = material;
  391. return debug_navigation_agent_path_point_material;
  392. }
  393. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_agents_radius_material() {
  394. if (debug_navigation_avoidance_agents_radius_material.is_valid()) {
  395. return debug_navigation_avoidance_agents_radius_material;
  396. }
  397. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  398. material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  399. material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
  400. material->set_albedo(debug_navigation_avoidance_agents_radius_color);
  401. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
  402. debug_navigation_avoidance_agents_radius_material = material;
  403. return debug_navigation_avoidance_agents_radius_material;
  404. }
  405. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_obstacles_radius_material() {
  406. if (debug_navigation_avoidance_obstacles_radius_material.is_valid()) {
  407. return debug_navigation_avoidance_obstacles_radius_material;
  408. }
  409. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  410. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  411. material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  412. material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  413. material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
  414. material->set_albedo(debug_navigation_avoidance_obstacles_radius_color);
  415. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
  416. debug_navigation_avoidance_obstacles_radius_material = material;
  417. return debug_navigation_avoidance_obstacles_radius_material;
  418. }
  419. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushin_face_material() {
  420. if (debug_navigation_avoidance_static_obstacle_pushin_face_material.is_valid()) {
  421. return debug_navigation_avoidance_static_obstacle_pushin_face_material;
  422. }
  423. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  424. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  425. material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  426. material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  427. material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
  428. material->set_albedo(debug_navigation_avoidance_static_obstacle_pushin_face_color);
  429. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
  430. debug_navigation_avoidance_static_obstacle_pushin_face_material = material;
  431. return debug_navigation_avoidance_static_obstacle_pushin_face_material;
  432. }
  433. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushout_face_material() {
  434. if (debug_navigation_avoidance_static_obstacle_pushout_face_material.is_valid()) {
  435. return debug_navigation_avoidance_static_obstacle_pushout_face_material;
  436. }
  437. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  438. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  439. material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  440. material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  441. material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
  442. material->set_albedo(debug_navigation_avoidance_static_obstacle_pushout_face_color);
  443. material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
  444. debug_navigation_avoidance_static_obstacle_pushout_face_material = material;
  445. return debug_navigation_avoidance_static_obstacle_pushout_face_material;
  446. }
  447. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushin_edge_material() {
  448. if (debug_navigation_avoidance_static_obstacle_pushin_edge_material.is_valid()) {
  449. return debug_navigation_avoidance_static_obstacle_pushin_edge_material;
  450. }
  451. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  452. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  453. material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  454. //material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  455. //material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
  456. material->set_albedo(debug_navigation_avoidance_static_obstacle_pushin_edge_color);
  457. //material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
  458. material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  459. debug_navigation_avoidance_static_obstacle_pushin_edge_material = material;
  460. return debug_navigation_avoidance_static_obstacle_pushin_edge_material;
  461. }
  462. Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushout_edge_material() {
  463. if (debug_navigation_avoidance_static_obstacle_pushout_edge_material.is_valid()) {
  464. return debug_navigation_avoidance_static_obstacle_pushout_edge_material;
  465. }
  466. Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  467. material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  468. material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  469. ///material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  470. //material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
  471. material->set_albedo(debug_navigation_avoidance_static_obstacle_pushout_edge_color);
  472. //material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
  473. material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
  474. debug_navigation_avoidance_static_obstacle_pushout_edge_material = material;
  475. return debug_navigation_avoidance_static_obstacle_pushout_edge_material;
  476. }
  477. void NavigationServer3D::set_debug_navigation_edge_connection_color(const Color &p_color) {
  478. debug_navigation_edge_connection_color = p_color;
  479. if (debug_navigation_edge_connections_material.is_valid()) {
  480. debug_navigation_edge_connections_material->set_albedo(debug_navigation_edge_connection_color);
  481. }
  482. }
  483. Color NavigationServer3D::get_debug_navigation_edge_connection_color() const {
  484. return debug_navigation_edge_connection_color;
  485. }
  486. void NavigationServer3D::set_debug_navigation_geometry_edge_color(const Color &p_color) {
  487. debug_navigation_geometry_edge_color = p_color;
  488. if (debug_navigation_geometry_edge_material.is_valid()) {
  489. debug_navigation_geometry_edge_material->set_albedo(debug_navigation_geometry_edge_color);
  490. }
  491. }
  492. Color NavigationServer3D::get_debug_navigation_geometry_edge_color() const {
  493. return debug_navigation_geometry_edge_color;
  494. }
  495. void NavigationServer3D::set_debug_navigation_geometry_face_color(const Color &p_color) {
  496. debug_navigation_geometry_face_color = p_color;
  497. if (debug_navigation_geometry_face_material.is_valid()) {
  498. debug_navigation_geometry_face_material->set_albedo(debug_navigation_geometry_face_color);
  499. }
  500. }
  501. Color NavigationServer3D::get_debug_navigation_geometry_face_color() const {
  502. return debug_navigation_geometry_face_color;
  503. }
  504. void NavigationServer3D::set_debug_navigation_geometry_edge_disabled_color(const Color &p_color) {
  505. debug_navigation_geometry_edge_disabled_color = p_color;
  506. if (debug_navigation_geometry_edge_disabled_material.is_valid()) {
  507. debug_navigation_geometry_edge_disabled_material->set_albedo(debug_navigation_geometry_edge_disabled_color);
  508. }
  509. }
  510. Color NavigationServer3D::get_debug_navigation_geometry_edge_disabled_color() const {
  511. return debug_navigation_geometry_edge_disabled_color;
  512. }
  513. void NavigationServer3D::set_debug_navigation_geometry_face_disabled_color(const Color &p_color) {
  514. debug_navigation_geometry_face_disabled_color = p_color;
  515. if (debug_navigation_geometry_face_disabled_material.is_valid()) {
  516. debug_navigation_geometry_face_disabled_material->set_albedo(debug_navigation_geometry_face_disabled_color);
  517. }
  518. }
  519. Color NavigationServer3D::get_debug_navigation_geometry_face_disabled_color() const {
  520. return debug_navigation_geometry_face_disabled_color;
  521. }
  522. void NavigationServer3D::set_debug_navigation_link_connection_color(const Color &p_color) {
  523. debug_navigation_link_connection_color = p_color;
  524. if (debug_navigation_link_connections_material.is_valid()) {
  525. debug_navigation_link_connections_material->set_albedo(debug_navigation_link_connection_color);
  526. }
  527. }
  528. Color NavigationServer3D::get_debug_navigation_link_connection_color() const {
  529. return debug_navigation_link_connection_color;
  530. }
  531. void NavigationServer3D::set_debug_navigation_link_connection_disabled_color(const Color &p_color) {
  532. debug_navigation_link_connection_disabled_color = p_color;
  533. if (debug_navigation_link_connections_disabled_material.is_valid()) {
  534. debug_navigation_link_connections_disabled_material->set_albedo(debug_navigation_link_connection_disabled_color);
  535. }
  536. }
  537. Color NavigationServer3D::get_debug_navigation_link_connection_disabled_color() const {
  538. return debug_navigation_link_connection_disabled_color;
  539. }
  540. void NavigationServer3D::set_debug_navigation_agent_path_point_size(real_t p_point_size) {
  541. debug_navigation_agent_path_point_size = MAX(0.1, p_point_size);
  542. if (debug_navigation_agent_path_point_material.is_valid()) {
  543. debug_navigation_agent_path_point_material->set_point_size(debug_navigation_agent_path_point_size);
  544. }
  545. }
  546. real_t NavigationServer3D::get_debug_navigation_agent_path_point_size() const {
  547. return debug_navigation_agent_path_point_size;
  548. }
  549. void NavigationServer3D::set_debug_navigation_agent_path_color(const Color &p_color) {
  550. debug_navigation_agent_path_color = p_color;
  551. if (debug_navigation_agent_path_line_material.is_valid()) {
  552. debug_navigation_agent_path_line_material->set_albedo(debug_navigation_agent_path_color);
  553. }
  554. if (debug_navigation_agent_path_point_material.is_valid()) {
  555. debug_navigation_agent_path_point_material->set_albedo(debug_navigation_agent_path_color);
  556. }
  557. }
  558. Color NavigationServer3D::get_debug_navigation_agent_path_color() const {
  559. return debug_navigation_agent_path_color;
  560. }
  561. void NavigationServer3D::set_debug_navigation_enable_edge_connections(const bool p_value) {
  562. debug_navigation_enable_edge_connections = p_value;
  563. navigation_debug_dirty = true;
  564. call_deferred("_emit_navigation_debug_changed_signal");
  565. }
  566. bool NavigationServer3D::get_debug_navigation_enable_edge_connections() const {
  567. return debug_navigation_enable_edge_connections;
  568. }
  569. void NavigationServer3D::set_debug_navigation_enable_edge_connections_xray(const bool p_value) {
  570. debug_navigation_enable_edge_connections_xray = p_value;
  571. if (debug_navigation_edge_connections_material.is_valid()) {
  572. debug_navigation_edge_connections_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_edge_connections_xray);
  573. }
  574. }
  575. bool NavigationServer3D::get_debug_navigation_enable_edge_connections_xray() const {
  576. return debug_navigation_enable_edge_connections_xray;
  577. }
  578. void NavigationServer3D::set_debug_navigation_enable_edge_lines(const bool p_value) {
  579. debug_navigation_enable_edge_lines = p_value;
  580. navigation_debug_dirty = true;
  581. call_deferred("_emit_navigation_debug_changed_signal");
  582. }
  583. bool NavigationServer3D::get_debug_navigation_enable_edge_lines() const {
  584. return debug_navigation_enable_edge_lines;
  585. }
  586. void NavigationServer3D::set_debug_navigation_enable_edge_lines_xray(const bool p_value) {
  587. debug_navigation_enable_edge_lines_xray = p_value;
  588. if (debug_navigation_geometry_edge_material.is_valid()) {
  589. debug_navigation_geometry_edge_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_edge_lines_xray);
  590. }
  591. }
  592. bool NavigationServer3D::get_debug_navigation_enable_edge_lines_xray() const {
  593. return debug_navigation_enable_edge_lines_xray;
  594. }
  595. void NavigationServer3D::set_debug_navigation_enable_geometry_face_random_color(const bool p_value) {
  596. debug_navigation_enable_geometry_face_random_color = p_value;
  597. navigation_debug_dirty = true;
  598. call_deferred("_emit_navigation_debug_changed_signal");
  599. }
  600. bool NavigationServer3D::get_debug_navigation_enable_geometry_face_random_color() const {
  601. return debug_navigation_enable_geometry_face_random_color;
  602. }
  603. void NavigationServer3D::set_debug_navigation_enable_link_connections(const bool p_value) {
  604. debug_navigation_enable_link_connections = p_value;
  605. navigation_debug_dirty = true;
  606. call_deferred("_emit_navigation_debug_changed_signal");
  607. }
  608. bool NavigationServer3D::get_debug_navigation_enable_link_connections() const {
  609. return debug_navigation_enable_link_connections;
  610. }
  611. void NavigationServer3D::set_debug_navigation_enable_link_connections_xray(const bool p_value) {
  612. debug_navigation_enable_link_connections_xray = p_value;
  613. if (debug_navigation_link_connections_material.is_valid()) {
  614. debug_navigation_link_connections_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_link_connections_xray);
  615. }
  616. }
  617. bool NavigationServer3D::get_debug_navigation_enable_link_connections_xray() const {
  618. return debug_navigation_enable_link_connections_xray;
  619. }
  620. void NavigationServer3D::set_debug_navigation_avoidance_enable_agents_radius(const bool p_value) {
  621. debug_navigation_avoidance_enable_agents_radius = p_value;
  622. avoidance_debug_dirty = true;
  623. call_deferred("_emit_avoidance_debug_changed_signal");
  624. }
  625. bool NavigationServer3D::get_debug_navigation_avoidance_enable_agents_radius() const {
  626. return debug_navigation_avoidance_enable_agents_radius;
  627. }
  628. void NavigationServer3D::set_debug_navigation_avoidance_enable_obstacles_radius(const bool p_value) {
  629. debug_navigation_avoidance_enable_obstacles_radius = p_value;
  630. avoidance_debug_dirty = true;
  631. call_deferred("_emit_avoidance_debug_changed_signal");
  632. }
  633. bool NavigationServer3D::get_debug_navigation_avoidance_enable_obstacles_radius() const {
  634. return debug_navigation_avoidance_enable_obstacles_radius;
  635. }
  636. void NavigationServer3D::set_debug_navigation_avoidance_enable_obstacles_static(const bool p_value) {
  637. debug_navigation_avoidance_enable_obstacles_static = p_value;
  638. avoidance_debug_dirty = true;
  639. call_deferred("_emit_avoidance_debug_changed_signal");
  640. }
  641. bool NavigationServer3D::get_debug_navigation_avoidance_enable_obstacles_static() const {
  642. return debug_navigation_avoidance_enable_obstacles_static;
  643. }
  644. void NavigationServer3D::set_debug_navigation_avoidance_agents_radius_color(const Color &p_color) {
  645. debug_navigation_avoidance_agents_radius_color = p_color;
  646. if (debug_navigation_avoidance_agents_radius_material.is_valid()) {
  647. debug_navigation_avoidance_agents_radius_material->set_albedo(debug_navigation_avoidance_agents_radius_color);
  648. }
  649. }
  650. Color NavigationServer3D::get_debug_navigation_avoidance_agents_radius_color() const {
  651. return debug_navigation_avoidance_agents_radius_color;
  652. }
  653. void NavigationServer3D::set_debug_navigation_avoidance_obstacles_radius_color(const Color &p_color) {
  654. debug_navigation_avoidance_obstacles_radius_color = p_color;
  655. if (debug_navigation_avoidance_obstacles_radius_material.is_valid()) {
  656. debug_navigation_avoidance_obstacles_radius_material->set_albedo(debug_navigation_avoidance_obstacles_radius_color);
  657. }
  658. }
  659. Color NavigationServer3D::get_debug_navigation_avoidance_obstacles_radius_color() const {
  660. return debug_navigation_avoidance_obstacles_radius_color;
  661. }
  662. void NavigationServer3D::set_debug_navigation_avoidance_static_obstacle_pushin_face_color(const Color &p_color) {
  663. debug_navigation_avoidance_static_obstacle_pushin_face_color = p_color;
  664. if (debug_navigation_avoidance_static_obstacle_pushin_face_material.is_valid()) {
  665. debug_navigation_avoidance_static_obstacle_pushin_face_material->set_albedo(debug_navigation_avoidance_static_obstacle_pushin_face_color);
  666. }
  667. }
  668. Color NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushin_face_color() const {
  669. return debug_navigation_avoidance_static_obstacle_pushin_face_color;
  670. }
  671. void NavigationServer3D::set_debug_navigation_avoidance_static_obstacle_pushout_face_color(const Color &p_color) {
  672. debug_navigation_avoidance_static_obstacle_pushout_face_color = p_color;
  673. if (debug_navigation_avoidance_static_obstacle_pushout_face_material.is_valid()) {
  674. debug_navigation_avoidance_static_obstacle_pushout_face_material->set_albedo(debug_navigation_avoidance_static_obstacle_pushout_face_color);
  675. }
  676. }
  677. Color NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushout_face_color() const {
  678. return debug_navigation_avoidance_static_obstacle_pushout_face_color;
  679. }
  680. void NavigationServer3D::set_debug_navigation_avoidance_static_obstacle_pushin_edge_color(const Color &p_color) {
  681. debug_navigation_avoidance_static_obstacle_pushin_edge_color = p_color;
  682. if (debug_navigation_avoidance_static_obstacle_pushin_edge_material.is_valid()) {
  683. debug_navigation_avoidance_static_obstacle_pushin_edge_material->set_albedo(debug_navigation_avoidance_static_obstacle_pushin_edge_color);
  684. }
  685. }
  686. Color NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushin_edge_color() const {
  687. return debug_navigation_avoidance_static_obstacle_pushin_edge_color;
  688. }
  689. void NavigationServer3D::set_debug_navigation_avoidance_static_obstacle_pushout_edge_color(const Color &p_color) {
  690. debug_navigation_avoidance_static_obstacle_pushout_edge_color = p_color;
  691. if (debug_navigation_avoidance_static_obstacle_pushout_edge_material.is_valid()) {
  692. debug_navigation_avoidance_static_obstacle_pushout_edge_material->set_albedo(debug_navigation_avoidance_static_obstacle_pushout_edge_color);
  693. }
  694. }
  695. Color NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushout_edge_color() const {
  696. return debug_navigation_avoidance_static_obstacle_pushout_edge_color;
  697. }
  698. void NavigationServer3D::set_debug_navigation_enable_agent_paths(const bool p_value) {
  699. if (debug_navigation_enable_agent_paths != p_value) {
  700. debug_dirty = true;
  701. }
  702. debug_navigation_enable_agent_paths = p_value;
  703. if (debug_dirty) {
  704. call_deferred("_emit_navigation_debug_changed_signal");
  705. }
  706. }
  707. bool NavigationServer3D::get_debug_navigation_enable_agent_paths() const {
  708. return debug_navigation_enable_agent_paths;
  709. }
  710. void NavigationServer3D::set_debug_navigation_enable_agent_paths_xray(const bool p_value) {
  711. debug_navigation_enable_agent_paths_xray = p_value;
  712. if (debug_navigation_agent_path_line_material.is_valid()) {
  713. debug_navigation_agent_path_line_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_agent_paths_xray);
  714. }
  715. if (debug_navigation_agent_path_point_material.is_valid()) {
  716. debug_navigation_agent_path_point_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_agent_paths_xray);
  717. }
  718. }
  719. bool NavigationServer3D::get_debug_navigation_enable_agent_paths_xray() const {
  720. return debug_navigation_enable_agent_paths_xray;
  721. }
  722. void NavigationServer3D::set_debug_navigation_enabled(bool p_enabled) {
  723. debug_navigation_enabled = p_enabled;
  724. navigation_debug_dirty = true;
  725. call_deferred("_emit_navigation_debug_changed_signal");
  726. }
  727. bool NavigationServer3D::get_debug_navigation_enabled() const {
  728. return debug_navigation_enabled;
  729. }
  730. void NavigationServer3D::set_debug_avoidance_enabled(bool p_enabled) {
  731. debug_avoidance_enabled = p_enabled;
  732. avoidance_debug_dirty = true;
  733. call_deferred("_emit_avoidance_debug_changed_signal");
  734. }
  735. bool NavigationServer3D::get_debug_avoidance_enabled() const {
  736. return debug_avoidance_enabled;
  737. }
  738. #endif // DEBUG_ENABLED
  739. void NavigationServer3D::query_path(const Ref<NavigationPathQueryParameters3D> &p_query_parameters, Ref<NavigationPathQueryResult3D> p_query_result) const {
  740. ERR_FAIL_COND(!p_query_parameters.is_valid());
  741. ERR_FAIL_COND(!p_query_result.is_valid());
  742. const NavigationUtilities::PathQueryResult _query_result = _query_path(p_query_parameters->get_parameters());
  743. p_query_result->set_path(_query_result.path);
  744. p_query_result->set_path_types(_query_result.path_types);
  745. p_query_result->set_path_rids(_query_result.path_rids);
  746. p_query_result->set_path_owner_ids(_query_result.path_owner_ids);
  747. }
  748. ///////////////////////////////////////////////////////
  749. NavigationServer3DCallback NavigationServer3DManager::create_callback = nullptr;
  750. void NavigationServer3DManager::set_default_server(NavigationServer3DCallback p_callback) {
  751. create_callback = p_callback;
  752. }
  753. NavigationServer3D *NavigationServer3DManager::new_default_server() {
  754. if (create_callback == nullptr) {
  755. return nullptr;
  756. }
  757. return create_callback();
  758. }