navigation_server_3d.cpp 55 KB

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