navigation_server_3d.cpp 55 KB

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