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