navigation_server_3d.cpp 55 KB

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