navigation_server_3d.cpp 58 KB

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