navigation_server_3d.cpp 64 KB

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