navigation_server_3d.cpp 64 KB

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