navigation_server_3d.cpp 64 KB

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