Debian Codegraph @

servers/navigation_3d/navigation_server_3d.cpp

raw symbols SCIP
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
31 #include "navigation_server_3d.h"
32 #include "navigation_server_3d.compat.inc"
33
34 #include "core/config/project_settings.h"
35 #include "scene/main/node.h"
36 #include "servers/navigation_3d/navigation_server_3d_dummy.h"
37
38 NavigationServer3D *NavigationServer3D::singleton = nullptr;
39
40 RWLock NavigationServer3D::geometry_parser_rwlock;
41 RID_Owner<NavMeshGeometryParser3D> NavigationServer3D::geometry_parser_owner;
42 LocalVector<NavMeshGeometryParser3D *> NavigationServer3D::generator_parsers;
43
44 void NavigationServer3D::_bind_methods() {
45 ClassDB::bind_method(D_METHOD("get_maps"), &NavigationServer3D::get_maps);
46
47 ClassDB::bind_method(D_METHOD("map_create"), &NavigationServer3D::map_create);
48 ClassDB::bind_method(D_METHOD("map_set_active", "map", "active"), &NavigationServer3D::map_set_active);
49 ClassDB::bind_method(D_METHOD("map_is_active", "map"), &NavigationServer3D::map_is_active);
50 ClassDB::bind_method(D_METHOD("map_set_up", "map", "up"), &NavigationServer3D::map_set_up);
51 ClassDB::bind_method(D_METHOD("map_get_up", "map"), &NavigationServer3D::map_get_up);
52 ClassDB::bind_method(D_METHOD("map_set_cell_size", "map", "cell_size"), &NavigationServer3D::map_set_cell_size);
53 ClassDB::bind_method(D_METHOD("map_get_cell_size", "map"), &NavigationServer3D::map_get_cell_size);
54 ClassDB::bind_method(D_METHOD("map_set_cell_height", "map", "cell_height"), &NavigationServer3D::map_set_cell_height);
55 ClassDB::bind_method(D_METHOD("map_get_cell_height", "map"), &NavigationServer3D::map_get_cell_height);
56 ClassDB::bind_method(D_METHOD("map_set_merge_rasterizer_cell_scale", "map", "scale"), &NavigationServer3D::map_set_merge_rasterizer_cell_scale);
57 ClassDB::bind_method(D_METHOD("map_get_merge_rasterizer_cell_scale", "map"), &NavigationServer3D::map_get_merge_rasterizer_cell_scale);
58 ClassDB::bind_method(D_METHOD("map_set_use_edge_connections", "map", "enabled"), &NavigationServer3D::map_set_use_edge_connections);
59 ClassDB::bind_method(D_METHOD("map_get_use_edge_connections", "map"), &NavigationServer3D::map_get_use_edge_connections);
60 ClassDB::bind_method(D_METHOD("map_set_edge_connection_margin", "map", "margin"), &NavigationServer3D::map_set_edge_connection_margin);
61 ClassDB::bind_method(D_METHOD("map_get_edge_connection_margin", "map"), &NavigationServer3D::map_get_edge_connection_margin);
62 ClassDB::bind_method(D_METHOD("map_set_link_connection_radius", "map", "radius"), &NavigationServer3D::map_set_link_connection_radius);
63 ClassDB::bind_method(D_METHOD("map_get_link_connection_radius", "map"), &NavigationServer3D::map_get_link_connection_radius);
64 ClassDB::bind_method(D_METHOD("map_get_path", "map", "origin", "destination", "optimize", "navigation_layers"), &NavigationServer3D::map_get_path, DEFVAL(1));
65 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));
66 ClassDB::bind_method(D_METHOD("map_get_closest_point", "map", "to_point"), &NavigationServer3D::map_get_closest_point);
67 ClassDB::bind_method(D_METHOD("map_get_closest_point_normal", "map", "to_point"), &NavigationServer3D::map_get_closest_point_normal);
68 ClassDB::bind_method(D_METHOD("map_get_closest_point_owner", "map", "to_point"), &NavigationServer3D::map_get_closest_point_owner);
69
70 ClassDB::bind_method(D_METHOD("map_get_links", "map"), &NavigationServer3D::map_get_links);
71 ClassDB::bind_method(D_METHOD("map_get_regions", "map"), &NavigationServer3D::map_get_regions);
72 ClassDB::bind_method(D_METHOD("map_get_agents", "map"), &NavigationServer3D::map_get_agents);
73 ClassDB::bind_method(D_METHOD("map_get_obstacles", "map"), &NavigationServer3D::map_get_obstacles);
74
75 ClassDB::bind_method(D_METHOD("map_force_update", "map"), &NavigationServer3D::map_force_update);
76 ClassDB::bind_method(D_METHOD("map_get_iteration_id", "map"), &NavigationServer3D::map_get_iteration_id);
77 ClassDB::bind_method(D_METHOD("map_set_use_async_iterations", "map", "enabled"), &NavigationServer3D::map_set_use_async_iterations);
78 ClassDB::bind_method(D_METHOD("map_get_use_async_iterations", "map"), &NavigationServer3D::map_get_use_async_iterations);
79
80 ClassDB::bind_method(D_METHOD("map_get_random_point", "map", "navigation_layers", "uniformly"), &NavigationServer3D::map_get_random_point);
81
82 ClassDB::bind_method(D_METHOD("query_path", "parameters", "result", "callback"), &NavigationServer3D::query_path, DEFVAL(Callable()));
83
84 ClassDB::bind_method(D_METHOD("region_create"), &NavigationServer3D::region_create);
85 ClassDB::bind_method(D_METHOD("region_get_iteration_id", "region"), &NavigationServer3D::region_get_iteration_id);
86 ClassDB::bind_method(D_METHOD("region_set_use_async_iterations", "region", "enabled"), &NavigationServer3D::region_set_use_async_iterations);
87 ClassDB::bind_method(D_METHOD("region_get_use_async_iterations", "region"), &NavigationServer3D::region_get_use_async_iterations);
88 ClassDB::bind_method(D_METHOD("region_set_enabled", "region", "enabled"), &NavigationServer3D::region_set_enabled);
89 ClassDB::bind_method(D_METHOD("region_get_enabled", "region"), &NavigationServer3D::region_get_enabled);
90 ClassDB::bind_method(D_METHOD("region_set_use_edge_connections", "region", "enabled"), &NavigationServer3D::region_set_use_edge_connections);
91 ClassDB::bind_method(D_METHOD("region_get_use_edge_connections", "region"), &NavigationServer3D::region_get_use_edge_connections);
92 ClassDB::bind_method(D_METHOD("region_set_enter_cost", "region", "enter_cost"), &NavigationServer3D::region_set_enter_cost);
93 ClassDB::bind_method(D_METHOD("region_get_enter_cost", "region"), &NavigationServer3D::region_get_enter_cost);
94 ClassDB::bind_method(D_METHOD("region_set_travel_cost", "region", "travel_cost"), &NavigationServer3D::region_set_travel_cost);
95 ClassDB::bind_method(D_METHOD("region_get_travel_cost", "region"), &NavigationServer3D::region_get_travel_cost);
96 ClassDB::bind_method(D_METHOD("region_set_owner_id", "region", "owner_id"), &NavigationServer3D::region_set_owner_id);
97 ClassDB::bind_method(D_METHOD("region_get_owner_id", "region"), &NavigationServer3D::region_get_owner_id);
98 ClassDB::bind_method(D_METHOD("region_owns_point", "region", "point"), &NavigationServer3D::region_owns_point);
99 ClassDB::bind_method(D_METHOD("region_set_map", "region", "map"), &NavigationServer3D::region_set_map);
100 ClassDB::bind_method(D_METHOD("region_get_map", "region"), &NavigationServer3D::region_get_map);
101 ClassDB::bind_method(D_METHOD("region_set_navigation_layers", "region", "navigation_layers"), &NavigationServer3D::region_set_navigation_layers);
102 ClassDB::bind_method(D_METHOD("region_get_navigation_layers", "region"), &NavigationServer3D::region_get_navigation_layers);
103 ClassDB::bind_method(D_METHOD("region_set_transform", "region", "transform"), &NavigationServer3D::region_set_transform);
104 ClassDB::bind_method(D_METHOD("region_get_transform", "region"), &NavigationServer3D::region_get_transform);
105 ClassDB::bind_method(D_METHOD("region_set_navigation_mesh", "region", "navigation_mesh"), &NavigationServer3D::region_set_navigation_mesh);
106 #ifndef DISABLE_DEPRECATED
107 ClassDB::bind_method(D_METHOD("region_bake_navigation_mesh", "navigation_mesh", "root_node"), &NavigationServer3D::region_bake_navigation_mesh);
108 #endif // DISABLE_DEPRECATED
109 ClassDB::bind_method(D_METHOD("region_get_connections_count", "region"), &NavigationServer3D::region_get_connections_count);
110 ClassDB::bind_method(D_METHOD("region_get_connection_pathway_start", "region", "connection"), &NavigationServer3D::region_get_connection_pathway_start);
111 ClassDB::bind_method(D_METHOD("region_get_connection_pathway_end", "region", "connection"), &NavigationServer3D::region_get_connection_pathway_end);
112 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));
113 ClassDB::bind_method(D_METHOD("region_get_closest_point", "region", "to_point"), &NavigationServer3D::region_get_closest_point);
114 ClassDB::bind_method(D_METHOD("region_get_closest_point_normal", "region", "to_point"), &NavigationServer3D::region_get_closest_point_normal);
115 ClassDB::bind_method(D_METHOD("region_get_random_point", "region", "navigation_layers", "uniformly"), &NavigationServer3D::region_get_random_point);
116 ClassDB::bind_method(D_METHOD("region_get_bounds", "region"), &NavigationServer3D::region_get_bounds);
117
118 ClassDB::bind_method(D_METHOD("link_create"), &NavigationServer3D::link_create);
119 ClassDB::bind_method(D_METHOD("link_get_iteration_id", "link"), &NavigationServer3D::link_get_iteration_id);
120 ClassDB::bind_method(D_METHOD("link_set_map", "link", "map"), &NavigationServer3D::link_set_map);
121 ClassDB::bind_method(D_METHOD("link_get_map", "link"), &NavigationServer3D::link_get_map);
122 ClassDB::bind_method(D_METHOD("link_set_enabled", "link", "enabled"), &NavigationServer3D::link_set_enabled);
123 ClassDB::bind_method(D_METHOD("link_get_enabled", "link"), &NavigationServer3D::link_get_enabled);
124 ClassDB::bind_method(D_METHOD("link_set_bidirectional", "link", "bidirectional"), &NavigationServer3D::link_set_bidirectional);
125 ClassDB::bind_method(D_METHOD("link_is_bidirectional", "link"), &NavigationServer3D::link_is_bidirectional);
126 ClassDB::bind_method(D_METHOD("link_set_navigation_layers", "link", "navigation_layers"), &NavigationServer3D::link_set_navigation_layers);
127 ClassDB::bind_method(D_METHOD("link_get_navigation_layers", "link"), &NavigationServer3D::link_get_navigation_layers);
128 ClassDB::bind_method(D_METHOD("link_set_start_position", "link", "position"), &NavigationServer3D::link_set_start_position);
129 ClassDB::bind_method(D_METHOD("link_get_start_position", "link"), &NavigationServer3D::link_get_start_position);
130 ClassDB::bind_method(D_METHOD("link_set_end_position", "link", "position"), &NavigationServer3D::link_set_end_position);
131 ClassDB::bind_method(D_METHOD("link_get_end_position", "link"), &NavigationServer3D::link_get_end_position);
132 ClassDB::bind_method(D_METHOD("link_set_enter_cost", "link", "enter_cost"), &NavigationServer3D::link_set_enter_cost);
133 ClassDB::bind_method(D_METHOD("link_get_enter_cost", "link"), &NavigationServer3D::link_get_enter_cost);
134 ClassDB::bind_method(D_METHOD("link_set_travel_cost", "link", "travel_cost"), &NavigationServer3D::link_set_travel_cost);
135 ClassDB::bind_method(D_METHOD("link_get_travel_cost", "link"), &NavigationServer3D::link_get_travel_cost);
136 ClassDB::bind_method(D_METHOD("link_set_owner_id", "link", "owner_id"), &NavigationServer3D::link_set_owner_id);
137 ClassDB::bind_method(D_METHOD("link_get_owner_id", "link"), &NavigationServer3D::link_get_owner_id);
138
139 ClassDB::bind_method(D_METHOD("agent_create"), &NavigationServer3D::agent_create);
140 ClassDB::bind_method(D_METHOD("agent_set_avoidance_enabled", "agent", "enabled"), &NavigationServer3D::agent_set_avoidance_enabled);
141 ClassDB::bind_method(D_METHOD("agent_get_avoidance_enabled", "agent"), &NavigationServer3D::agent_get_avoidance_enabled);
142 ClassDB::bind_method(D_METHOD("agent_set_use_3d_avoidance", "agent", "enabled"), &NavigationServer3D::agent_set_use_3d_avoidance);
143 ClassDB::bind_method(D_METHOD("agent_get_use_3d_avoidance", "agent"), &NavigationServer3D::agent_get_use_3d_avoidance);
144
145 ClassDB::bind_method(D_METHOD("agent_set_map", "agent", "map"), &NavigationServer3D::agent_set_map);
146 ClassDB::bind_method(D_METHOD("agent_get_map", "agent"), &NavigationServer3D::agent_get_map);
147 ClassDB::bind_method(D_METHOD("agent_set_paused", "agent", "paused"), &NavigationServer3D::agent_set_paused);
148 ClassDB::bind_method(D_METHOD("agent_get_paused", "agent"), &NavigationServer3D::agent_get_paused);
149 ClassDB::bind_method(D_METHOD("agent_set_neighbor_distance", "agent", "distance"), &NavigationServer3D::agent_set_neighbor_distance);
150 ClassDB::bind_method(D_METHOD("agent_get_neighbor_distance", "agent"), &NavigationServer3D::agent_get_neighbor_distance);
151 ClassDB::bind_method(D_METHOD("agent_set_max_neighbors", "agent", "count"), &NavigationServer3D::agent_set_max_neighbors);
152 ClassDB::bind_method(D_METHOD("agent_get_max_neighbors", "agent"), &NavigationServer3D::agent_get_max_neighbors);
153 ClassDB::bind_method(D_METHOD("agent_set_time_horizon_agents", "agent", "time_horizon"), &NavigationServer3D::agent_set_time_horizon_agents);
154 ClassDB::bind_method(D_METHOD("agent_get_time_horizon_agents", "agent"), &NavigationServer3D::agent_get_time_horizon_agents);
155 ClassDB::bind_method(D_METHOD("agent_set_time_horizon_obstacles", "agent", "time_horizon"), &NavigationServer3D::agent_set_time_horizon_obstacles);
156 ClassDB::bind_method(D_METHOD("agent_get_time_horizon_obstacles", "agent"), &NavigationServer3D::agent_get_time_horizon_obstacles);
157 ClassDB::bind_method(D_METHOD("agent_set_radius", "agent", "radius"), &NavigationServer3D::agent_set_radius);
158 ClassDB::bind_method(D_METHOD("agent_get_radius", "agent"), &NavigationServer3D::agent_get_radius);
159 ClassDB::bind_method(D_METHOD("agent_set_height", "agent", "height"), &NavigationServer3D::agent_set_height);
160 ClassDB::bind_method(D_METHOD("agent_get_height", "agent"), &NavigationServer3D::agent_get_height);
161 ClassDB::bind_method(D_METHOD("agent_set_max_speed", "agent", "max_speed"), &NavigationServer3D::agent_set_max_speed);
162 ClassDB::bind_method(D_METHOD("agent_get_max_speed", "agent"), &NavigationServer3D::agent_get_max_speed);
163 ClassDB::bind_method(D_METHOD("agent_set_velocity_forced", "agent", "velocity"), &NavigationServer3D::agent_set_velocity_forced);
164 ClassDB::bind_method(D_METHOD("agent_set_velocity", "agent", "velocity"), &NavigationServer3D::agent_set_velocity);
165 ClassDB::bind_method(D_METHOD("agent_get_velocity", "agent"), &NavigationServer3D::agent_get_velocity);
166 ClassDB::bind_method(D_METHOD("agent_set_position", "agent", "position"), &NavigationServer3D::agent_set_position);
167 ClassDB::bind_method(D_METHOD("agent_get_position", "agent"), &NavigationServer3D::agent_get_position);
168 ClassDB::bind_method(D_METHOD("agent_is_map_changed", "agent"), &NavigationServer3D::agent_is_map_changed);
169 ClassDB::bind_method(D_METHOD("agent_set_avoidance_callback", "agent", "callback"), &NavigationServer3D::agent_set_avoidance_callback);
170 ClassDB::bind_method(D_METHOD("agent_has_avoidance_callback", "agent"), &NavigationServer3D::agent_has_avoidance_callback);
171 ClassDB::bind_method(D_METHOD("agent_set_avoidance_layers", "agent", "layers"), &NavigationServer3D::agent_set_avoidance_layers);
172 ClassDB::bind_method(D_METHOD("agent_get_avoidance_layers", "agent"), &NavigationServer3D::agent_get_avoidance_layers);
173 ClassDB::bind_method(D_METHOD("agent_set_avoidance_mask", "agent", "mask"), &NavigationServer3D::agent_set_avoidance_mask);
174 ClassDB::bind_method(D_METHOD("agent_get_avoidance_mask", "agent"), &NavigationServer3D::agent_get_avoidance_mask);
175 ClassDB::bind_method(D_METHOD("agent_set_avoidance_priority", "agent", "priority"), &NavigationServer3D::agent_set_avoidance_priority);
176 ClassDB::bind_method(D_METHOD("agent_get_avoidance_priority", "agent"), &NavigationServer3D::agent_get_avoidance_priority);
177
178 ClassDB::bind_method(D_METHOD("obstacle_create"), &NavigationServer3D::obstacle_create);
179 ClassDB::bind_method(D_METHOD("obstacle_set_avoidance_enabled", "obstacle", "enabled"), &NavigationServer3D::obstacle_set_avoidance_enabled);
180 ClassDB::bind_method(D_METHOD("obstacle_get_avoidance_enabled", "obstacle"), &NavigationServer3D::obstacle_get_avoidance_enabled);
181 ClassDB::bind_method(D_METHOD("obstacle_set_use_3d_avoidance", "obstacle", "enabled"), &NavigationServer3D::obstacle_set_use_3d_avoidance);
182 ClassDB::bind_method(D_METHOD("obstacle_get_use_3d_avoidance", "obstacle"), &NavigationServer3D::obstacle_get_use_3d_avoidance);
183 ClassDB::bind_method(D_METHOD("obstacle_set_map", "obstacle", "map"), &NavigationServer3D::obstacle_set_map);
184 ClassDB::bind_method(D_METHOD("obstacle_get_map", "obstacle"), &NavigationServer3D::obstacle_get_map);
185 ClassDB::bind_method(D_METHOD("obstacle_set_paused", "obstacle", "paused"), &NavigationServer3D::obstacle_set_paused);
186 ClassDB::bind_method(D_METHOD("obstacle_get_paused", "obstacle"), &NavigationServer3D::obstacle_get_paused);
187 ClassDB::bind_method(D_METHOD("obstacle_set_radius", "obstacle", "radius"), &NavigationServer3D::obstacle_set_radius);
188 ClassDB::bind_method(D_METHOD("obstacle_get_radius", "obstacle"), &NavigationServer3D::obstacle_get_radius);
189 ClassDB::bind_method(D_METHOD("obstacle_set_height", "obstacle", "height"), &NavigationServer3D::obstacle_set_height);
190 ClassDB::bind_method(D_METHOD("obstacle_get_height", "obstacle"), &NavigationServer3D::obstacle_get_height);
191 ClassDB::bind_method(D_METHOD("obstacle_set_velocity", "obstacle", "velocity"), &NavigationServer3D::obstacle_set_velocity);
192 ClassDB::bind_method(D_METHOD("obstacle_get_velocity", "obstacle"), &NavigationServer3D::obstacle_get_velocity);
193 ClassDB::bind_method(D_METHOD("obstacle_set_position", "obstacle", "position"), &NavigationServer3D::obstacle_set_position);
194 ClassDB::bind_method(D_METHOD("obstacle_get_position", "obstacle"), &NavigationServer3D::obstacle_get_position);
195 ClassDB::bind_method(D_METHOD("obstacle_set_vertices", "obstacle", "vertices"), &NavigationServer3D::obstacle_set_vertices);
196 ClassDB::bind_method(D_METHOD("obstacle_get_vertices", "obstacle"), &NavigationServer3D::obstacle_get_vertices);
197 ClassDB::bind_method(D_METHOD("obstacle_set_avoidance_layers", "obstacle", "layers"), &NavigationServer3D::obstacle_set_avoidance_layers);
198 ClassDB::bind_method(D_METHOD("obstacle_get_avoidance_layers", "obstacle"), &NavigationServer3D::obstacle_get_avoidance_layers);
199
200 #ifndef _3D_DISABLED
201 ClassDB::bind_method(D_METHOD("parse_source_geometry_data", "navigation_mesh", "source_geometry_data", "root_node", "callback"), &NavigationServer3D::parse_source_geometry_data, DEFVAL(Callable()));
202 ClassDB::bind_method(D_METHOD("bake_from_source_geometry_data", "navigation_mesh", "source_geometry_data", "callback"), &NavigationServer3D::bake_from_source_geometry_data, DEFVAL(Callable()));
203 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()));
204 ClassDB::bind_method(D_METHOD("is_baking_navigation_mesh", "navigation_mesh"), &NavigationServer3D::is_baking_navigation_mesh);
205 #endif // _3D_DISABLED
206
207 ClassDB::bind_method(D_METHOD("source_geometry_parser_create"), &NavigationServer3D::source_geometry_parser_create);
208 ClassDB::bind_method(D_METHOD("source_geometry_parser_set_callback", "parser", "callback"), &NavigationServer3D::source_geometry_parser_set_callback);
209
210 ClassDB::bind_method(D_METHOD("simplify_path", "path", "epsilon"), &NavigationServer3D::simplify_path);
211
212 ClassDB::bind_method(D_METHOD("free_rid", "rid"), &NavigationServer3D::free_rid);
213
214 ClassDB::bind_method(D_METHOD("set_active", "active"), &NavigationServer3D::set_active);
215
216 ClassDB::bind_method(D_METHOD("set_debug_enabled", "enabled"), &NavigationServer3D::set_debug_enabled);
217 ClassDB::bind_method(D_METHOD("get_debug_enabled"), &NavigationServer3D::get_debug_enabled);
218
219 ADD_SIGNAL(MethodInfo("map_changed", PropertyInfo(Variant::RID, "map")));
220
221 ADD_SIGNAL(MethodInfo("navigation_debug_changed"));
222 ADD_SIGNAL(MethodInfo("avoidance_debug_changed"));
223
224 ClassDB::bind_method(D_METHOD("get_process_info", "process_info"), &NavigationServer3D::get_process_info);
225
226 BIND_ENUM_CONSTANT(INFO_ACTIVE_MAPS);
227 BIND_ENUM_CONSTANT(INFO_REGION_COUNT);
228 BIND_ENUM_CONSTANT(INFO_AGENT_COUNT);
229 BIND_ENUM_CONSTANT(INFO_LINK_COUNT);
230 BIND_ENUM_CONSTANT(INFO_POLYGON_COUNT);
231 BIND_ENUM_CONSTANT(INFO_EDGE_COUNT);
232 BIND_ENUM_CONSTANT(INFO_EDGE_MERGE_COUNT);
233 BIND_ENUM_CONSTANT(INFO_EDGE_CONNECTION_COUNT);
234 BIND_ENUM_CONSTANT(INFO_EDGE_FREE_COUNT);
235 BIND_ENUM_CONSTANT(INFO_OBSTACLE_COUNT);
236 }
237
238 NavigationServer3D *NavigationServer3D::get_singleton() {
239 return singleton;
240 }
241
242 NavigationServer3D::NavigationServer3D() {
243 ERR_FAIL_COND(singleton != nullptr);
244 singleton = this;
245
246 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);
247 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);
248 GLOBAL_DEF("navigation/3d/default_up", Vector3(0, 1, 0));
249 GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "navigation/3d/merge_rasterizer_cell_scale", PROPERTY_HINT_RANGE, "0.001,1,0.001,or_greater"), 1.0);
250 GLOBAL_DEF("navigation/3d/use_edge_connections", true);
251 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);
252 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);
253
254 #ifdef DEBUG_ENABLED
255 #ifndef DISABLE_DEPRECATED
256 #define MOVE_PROJECT_SETTING_1(m_old_setting, m_new_setting) \
257 if (!ProjectSettings::get_singleton()->has_setting(m_new_setting) && ProjectSettings::get_singleton()->has_setting(m_old_setting)) { \
258 Variant value = GLOBAL_GET(m_old_setting); \
259 ProjectSettings::get_singleton()->set_setting(m_new_setting, value); \
260 ProjectSettings::get_singleton()->clear(m_old_setting); \
261 }
262 #define MOVE_PROJECT_SETTING_2(m_old_setting, m_new_setting_1, m_new_setting_2) \
263 if ((!ProjectSettings::get_singleton()->has_setting(m_new_setting_1) || !ProjectSettings::get_singleton()->has_setting(m_new_setting_2)) && \
264 ProjectSettings::get_singleton()->has_setting(m_old_setting)) { \
265 Variant value = GLOBAL_GET(m_old_setting); \
266 if (!ProjectSettings::get_singleton()->has_setting(m_new_setting_1)) { \
267 ProjectSettings::get_singleton()->set_setting(m_new_setting_1, value); \
268 } \
269 if (!ProjectSettings::get_singleton()->has_setting(m_new_setting_2)) { \
270 ProjectSettings::get_singleton()->set_setting(m_new_setting_2, value); \
271 } \
272 ProjectSettings::get_singleton()->clear(m_old_setting); \
273 }
274 MOVE_PROJECT_SETTING_2("debug/shapes/navigation/edge_connection_color", "debug/shapes/navigation/2d/edge_connection_color", "debug/shapes/navigation/3d/edge_connection_color");
275 MOVE_PROJECT_SETTING_2("debug/shapes/navigation/geometry_edge_color", "debug/shapes/navigation/2d/geometry_edge_color", "debug/shapes/navigation/3d/geometry_edge_color");
276 MOVE_PROJECT_SETTING_2("debug/shapes/navigation/geometry_face_color", "debug/shapes/navigation/2d/geometry_face_color", "debug/shapes/navigation/3d/geometry_face_color");
277 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");
278 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");
279 MOVE_PROJECT_SETTING_2("debug/shapes/navigation/link_connection_color", "debug/shapes/navigation/2d/link_connection_color", "debug/shapes/navigation/3d/link_connection_color");
280 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");
281 MOVE_PROJECT_SETTING_2("debug/shapes/navigation/agent_path_color", "debug/shapes/navigation/2d/agent_path_color", "debug/shapes/navigation/3d/agent_path_color");
282
283 MOVE_PROJECT_SETTING_2("debug/shapes/navigation/enable_edge_connections", "debug/shapes/navigation/2d/enable_edge_connections", "debug/shapes/navigation/3d/enable_edge_connections");
284 MOVE_PROJECT_SETTING_1("debug/shapes/navigation/enable_edge_connections_xray", "debug/shapes/navigation/3d/enable_edge_connections_xray");
285 MOVE_PROJECT_SETTING_2("debug/shapes/navigation/enable_edge_lines", "debug/shapes/navigation/2d/enable_edge_lines", "debug/shapes/navigation/3d/enable_edge_lines");
286 MOVE_PROJECT_SETTING_1("debug/shapes/navigation/enable_edge_lines_xray", "debug/shapes/navigation/3d/enable_edge_lines_xray");
287 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");
288 MOVE_PROJECT_SETTING_2("debug/shapes/navigation/enable_link_connections", "debug/shapes/navigation/2d/enable_link_connections", "debug/shapes/navigation/3d/enable_link_connections");
289 MOVE_PROJECT_SETTING_1("debug/shapes/navigation/enable_link_connections_xray", "debug/shapes/navigation/3d/enable_link_connections_xray");
290
291 MOVE_PROJECT_SETTING_2("debug/shapes/navigation/enable_agent_paths", "debug/shapes/navigation/2d/enable_agent_paths", "debug/shapes/navigation/3d/enable_agent_paths");
292 MOVE_PROJECT_SETTING_1("debug/shapes/navigation/enable_agent_paths_xray", "debug/shapes/navigation/3d/enable_agent_paths_xray");
293 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");
294
295 MOVE_PROJECT_SETTING_2("debug/shapes/avoidance/agents_radius_color", "debug/shapes/avoidance/2d/agents_radius_color", "debug/shapes/avoidance/3d/agents_radius_color");
296 MOVE_PROJECT_SETTING_2("debug/shapes/avoidance/obstacles_radius_color", "debug/shapes/avoidance/2d/obstacles_radius_color", "debug/shapes/avoidance/3d/obstacles_radius_color");
297 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");
298 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");
299 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");
300 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");
301 MOVE_PROJECT_SETTING_2("debug/shapes/avoidance/enable_agents_radius", "debug/shapes/avoidance/2d/enable_agents_radius", "debug/shapes/avoidance/3d/enable_agents_radius");
302 MOVE_PROJECT_SETTING_2("debug/shapes/avoidance/enable_obstacles_radius", "debug/shapes/avoidance/2d/enable_obstacles_radius", "debug/shapes/avoidance/2d/enable_obstacles_static");
303 MOVE_PROJECT_SETTING_2("debug/shapes/avoidance/enable_obstacles_radius", "debug/shapes/avoidance/3d/enable_obstacles_radius", "debug/shapes/avoidance/3d/enable_obstacles_static");
304 #undef MOVE_PROJECT_SETTING_1
305 #undef MOVE_PROJECT_SETTING_2
306 #endif // DISABLE_DEPRECATED
307
308 debug_navigation_edge_connection_color = GLOBAL_DEF("debug/shapes/navigation/3d/edge_connection_color", Color(1.0, 0.0, 1.0, 1.0));
309 debug_navigation_geometry_edge_color = GLOBAL_DEF("debug/shapes/navigation/3d/geometry_edge_color", Color(0.5, 1.0, 1.0, 1.0));
310 debug_navigation_geometry_face_color = GLOBAL_DEF("debug/shapes/navigation/3d/geometry_face_color", Color(0.5, 1.0, 1.0, 0.4));
311 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));
312 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));
313 debug_navigation_link_connection_color = GLOBAL_DEF("debug/shapes/navigation/3d/link_connection_color", Color(1.0, 0.5, 1.0, 1.0));
314 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));
315 debug_navigation_agent_path_color = GLOBAL_DEF("debug/shapes/navigation/3d/agent_path_color", Color(1.0, 0.0, 0.0, 1.0));
316
317 debug_navigation_enable_edge_connections = GLOBAL_DEF("debug/shapes/navigation/3d/enable_edge_connections", true);
318 debug_navigation_enable_edge_connections_xray = GLOBAL_DEF("debug/shapes/navigation/3d/enable_edge_connections_xray", true);
319 debug_navigation_enable_edge_lines = GLOBAL_DEF("debug/shapes/navigation/3d/enable_edge_lines", true);
320 debug_navigation_enable_edge_lines_xray = GLOBAL_DEF("debug/shapes/navigation/3d/enable_edge_lines_xray", true);
321 debug_navigation_enable_geometry_face_random_color = GLOBAL_DEF("debug/shapes/navigation/3d/enable_geometry_face_random_color", true);
322 debug_navigation_enable_link_connections = GLOBAL_DEF("debug/shapes/navigation/3d/enable_link_connections", true);
323 debug_navigation_enable_link_connections_xray = GLOBAL_DEF("debug/shapes/navigation/3d/enable_link_connections_xray", true);
324
325 debug_navigation_enable_agent_paths = GLOBAL_DEF("debug/shapes/navigation/3d/enable_agent_paths", true);
326 debug_navigation_enable_agent_paths_xray = GLOBAL_DEF("debug/shapes/navigation/3d/enable_agent_paths_xray", true);
327 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);
328
329 debug_navigation_avoidance_agents_radius_color = GLOBAL_DEF("debug/shapes/avoidance/3d/agents_radius_color", Color(1.0, 1.0, 0.0, 0.25));
330 debug_navigation_avoidance_obstacles_radius_color = GLOBAL_DEF("debug/shapes/avoidance/3d/obstacles_radius_color", Color(1.0, 0.5, 0.0, 0.25));
331 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));
332 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));
333 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));
334 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));
335 debug_navigation_avoidance_enable_agents_radius = GLOBAL_DEF("debug/shapes/avoidance/3d/enable_agents_radius", true);
336 debug_navigation_avoidance_enable_obstacles_radius = GLOBAL_DEF("debug/shapes/avoidance/3d/enable_obstacles_radius", true);
337 debug_navigation_avoidance_enable_obstacles_static = GLOBAL_DEF("debug/shapes/avoidance/3d/enable_obstacles_static", true);
338
339 if (Engine::get_singleton()->is_editor_hint()) {
340 // enable NavigationServer3D when in Editor or else navigation mesh edge connections are invisible
341 // on runtime tests SceneTree has "Visible Navigation" set and main iteration takes care of this
342 set_debug_enabled(true);
343 set_debug_navigation_enabled(true);
344 set_debug_avoidance_enabled(true);
345 }
346 #endif // DEBUG_ENABLED
347 }
348
349 NavigationServer3D::~NavigationServer3D() {
350 singleton = nullptr;
351
352 RWLockWrite write_lock(geometry_parser_rwlock);
353 for (NavMeshGeometryParser3D *parser : generator_parsers) {
354 geometry_parser_owner.free(parser->self);
355 }
356 generator_parsers.clear();
357 }
358
359 RID NavigationServer3D::source_geometry_parser_create() {
360 RWLockWrite write_lock(geometry_parser_rwlock);
361
362 RID rid = geometry_parser_owner.make_rid();
363
364 NavMeshGeometryParser3D *parser = geometry_parser_owner.get_or_null(rid);
365 parser->self = rid;
366
367 generator_parsers.push_back(parser);
368
369 return rid;
370 }
371
372 void NavigationServer3D::free_rid(RID p_rid) {
373 if (!geometry_parser_owner.owns(p_rid)) {
374 return;
375 }
376 RWLockWrite write_lock(geometry_parser_rwlock);
377
378 NavMeshGeometryParser3D *parser = geometry_parser_owner.get_or_null(p_rid);
379 ERR_FAIL_NULL(parser);
380
381 generator_parsers.erase(parser);
382 geometry_parser_owner.free(parser->self);
383 }
384
385 void NavigationServer3D::source_geometry_parser_set_callback(RID p_parser, const Callable &p_callback) {
386 RWLockWrite write_lock(geometry_parser_rwlock);
387
388 NavMeshGeometryParser3D *parser = geometry_parser_owner.get_or_null(p_parser);
389 ERR_FAIL_NULL(parser);
390
391 parser->callback = p_callback;
392 }
393
394 void NavigationServer3D::set_debug_enabled(bool p_enabled) {
395 #ifdef DEBUG_ENABLED
396 if (debug_enabled != p_enabled) {
397 debug_dirty = true;
398 }
399
400 debug_enabled = p_enabled;
401
402 if (debug_dirty) {
403 navigation_debug_dirty = true;
404 callable_mp(this, &NavigationServer3D::_emit_navigation_debug_changed_signal).call_deferred();
405
406 avoidance_debug_dirty = true;
407 callable_mp(this, &NavigationServer3D::_emit_avoidance_debug_changed_signal).call_deferred();
408 }
409 #endif // DEBUG_ENABLED
410 }
411
412 bool NavigationServer3D::get_debug_enabled() const {
413 return debug_enabled;
414 }
415
416 #ifdef DEBUG_ENABLED
417 void NavigationServer3D::_emit_navigation_debug_changed_signal() {
418 if (navigation_debug_dirty) {
419 navigation_debug_dirty = false;
420 emit_signal(SNAME("navigation_debug_changed"));
421 }
422 }
423
424 void NavigationServer3D::_emit_avoidance_debug_changed_signal() {
425 if (avoidance_debug_dirty) {
426 avoidance_debug_dirty = false;
427 emit_signal(SNAME("avoidance_debug_changed"));
428 }
429 }
430 #endif // DEBUG_ENABLED
431
432 #ifdef DEBUG_ENABLED
433 Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_geometry_face_material() {
434 if (debug_navigation_geometry_face_material.is_valid()) {
435 return debug_navigation_geometry_face_material;
436 }
437
438 bool enabled_geometry_face_random_color = get_debug_navigation_enable_geometry_face_random_color();
439
440 Ref<StandardMaterial3D> face_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
441 face_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
442 face_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
443 face_material->set_albedo(get_debug_navigation_geometry_face_color());
444 face_material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
445 face_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
446 if (enabled_geometry_face_random_color) {
447 face_material->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true);
448 face_material->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
449 }
450
451 debug_navigation_geometry_face_material = face_material;
452
453 return debug_navigation_geometry_face_material;
454 }
455
456 Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_geometry_edge_material() {
457 if (debug_navigation_geometry_edge_material.is_valid()) {
458 return debug_navigation_geometry_edge_material;
459 }
460
461 bool enabled_edge_lines_xray = get_debug_navigation_enable_edge_lines_xray();
462
463 Ref<StandardMaterial3D> line_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
464 line_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
465 line_material->set_albedo(get_debug_navigation_geometry_edge_color());
466 line_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
467 if (enabled_edge_lines_xray) {
468 line_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
469 }
470
471 debug_navigation_geometry_edge_material = line_material;
472
473 return debug_navigation_geometry_edge_material;
474 }
475
476 Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_geometry_face_disabled_material() {
477 if (debug_navigation_geometry_face_disabled_material.is_valid()) {
478 return debug_navigation_geometry_face_disabled_material;
479 }
480
481 Ref<StandardMaterial3D> face_disabled_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
482 face_disabled_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
483 face_disabled_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
484 face_disabled_material->set_albedo(get_debug_navigation_geometry_face_disabled_color());
485 face_disabled_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
486
487 debug_navigation_geometry_face_disabled_material = face_disabled_material;
488
489 return debug_navigation_geometry_face_disabled_material;
490 }
491
492 Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_geometry_edge_disabled_material() {
493 if (debug_navigation_geometry_edge_disabled_material.is_valid()) {
494 return debug_navigation_geometry_edge_disabled_material;
495 }
496
497 bool enabled_edge_lines_xray = get_debug_navigation_enable_edge_lines_xray();
498
499 Ref<StandardMaterial3D> line_disabled_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
500 line_disabled_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
501 line_disabled_material->set_albedo(get_debug_navigation_geometry_edge_disabled_color());
502 line_disabled_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
503 if (enabled_edge_lines_xray) {
504 line_disabled_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
505 }
506
507 debug_navigation_geometry_edge_disabled_material = line_disabled_material;
508
509 return debug_navigation_geometry_edge_disabled_material;
510 }
511
512 Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_edge_connections_material() {
513 if (debug_navigation_edge_connections_material.is_valid()) {
514 return debug_navigation_edge_connections_material;
515 }
516
517 bool enabled_edge_connections_xray = get_debug_navigation_enable_edge_connections_xray();
518
519 Ref<StandardMaterial3D> edge_connections_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
520 edge_connections_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
521 edge_connections_material->set_albedo(get_debug_navigation_edge_connection_color());
522 edge_connections_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
523 if (enabled_edge_connections_xray) {
524 edge_connections_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
525 }
526 edge_connections_material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);
527
528 debug_navigation_edge_connections_material = edge_connections_material;
529
530 return debug_navigation_edge_connections_material;
531 }
532
533 Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_link_connections_material() {
534 if (debug_navigation_link_connections_material.is_valid()) {
535 return debug_navigation_link_connections_material;
536 }
537
538 Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
539 material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
540 material->set_albedo(debug_navigation_link_connection_color);
541 material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
542 if (debug_navigation_enable_link_connections_xray) {
543 material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
544 }
545 material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);
546
547 debug_navigation_link_connections_material = material;
548 return debug_navigation_link_connections_material;
549 }
550
551 Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_link_connections_disabled_material() {
552 if (debug_navigation_link_connections_disabled_material.is_valid()) {
553 return debug_navigation_link_connections_disabled_material;
554 }
555
556 Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
557 material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
558 material->set_albedo(debug_navigation_link_connection_disabled_color);
559 material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
560 if (debug_navigation_enable_link_connections_xray) {
561 material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
562 }
563 material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);
564
565 debug_navigation_link_connections_disabled_material = material;
566 return debug_navigation_link_connections_disabled_material;
567 }
568
569 Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_agent_path_line_material() {
570 if (debug_navigation_agent_path_line_material.is_valid()) {
571 return debug_navigation_agent_path_line_material;
572 }
573
574 Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
575 material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
576
577 material->set_albedo(debug_navigation_agent_path_color);
578 material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
579 if (debug_navigation_enable_agent_paths_xray) {
580 material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
581 }
582 material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);
583
584 debug_navigation_agent_path_line_material = material;
585 return debug_navigation_agent_path_line_material;
586 }
587
588 Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_agent_path_point_material() {
589 if (debug_navigation_agent_path_point_material.is_valid()) {
590 return debug_navigation_agent_path_point_material;
591 }
592
593 Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
594 material->set_albedo(debug_navigation_agent_path_color);
595 material->set_flag(StandardMaterial3D::FLAG_USE_POINT_SIZE, true);
596 material->set_point_size(debug_navigation_agent_path_point_size);
597 material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
598 if (debug_navigation_enable_agent_paths_xray) {
599 material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
600 }
601 material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);
602
603 debug_navigation_agent_path_point_material = material;
604 return debug_navigation_agent_path_point_material;
605 }
606
607 Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_agents_radius_material() {
608 if (debug_navigation_avoidance_agents_radius_material.is_valid()) {
609 return debug_navigation_avoidance_agents_radius_material;
610 }
611
612 Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
613 material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
614 material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
615 material->set_albedo(debug_navigation_avoidance_agents_radius_color);
616 material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
617
618 debug_navigation_avoidance_agents_radius_material = material;
619 return debug_navigation_avoidance_agents_radius_material;
620 }
621
622 Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_obstacles_radius_material() {
623 if (debug_navigation_avoidance_obstacles_radius_material.is_valid()) {
624 return debug_navigation_avoidance_obstacles_radius_material;
625 }
626
627 Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
628 material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
629 material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
630 material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
631 material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
632 material->set_albedo(debug_navigation_avoidance_obstacles_radius_color);
633 material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
634
635 debug_navigation_avoidance_obstacles_radius_material = material;
636 return debug_navigation_avoidance_obstacles_radius_material;
637 }
638
639 Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushin_face_material() {
640 if (debug_navigation_avoidance_static_obstacle_pushin_face_material.is_valid()) {
641 return debug_navigation_avoidance_static_obstacle_pushin_face_material;
642 }
643
644 Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
645 material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
646 material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
647 material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
648 material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
649 material->set_albedo(debug_navigation_avoidance_static_obstacle_pushin_face_color);
650 material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
651
652 debug_navigation_avoidance_static_obstacle_pushin_face_material = material;
653 return debug_navigation_avoidance_static_obstacle_pushin_face_material;
654 }
655
656 Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushout_face_material() {
657 if (debug_navigation_avoidance_static_obstacle_pushout_face_material.is_valid()) {
658 return debug_navigation_avoidance_static_obstacle_pushout_face_material;
659 }
660
661 Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
662 material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
663 material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
664 material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
665 material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
666 material->set_albedo(debug_navigation_avoidance_static_obstacle_pushout_face_color);
667 material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
668
669 debug_navigation_avoidance_static_obstacle_pushout_face_material = material;
670 return debug_navigation_avoidance_static_obstacle_pushout_face_material;
671 }
672
673 Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushin_edge_material() {
674 if (debug_navigation_avoidance_static_obstacle_pushin_edge_material.is_valid()) {
675 return debug_navigation_avoidance_static_obstacle_pushin_edge_material;
676 }
677
678 Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
679 material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
680 material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
681 //material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
682 //material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
683 material->set_albedo(debug_navigation_avoidance_static_obstacle_pushin_edge_color);
684 //material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
685 material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
686
687 debug_navigation_avoidance_static_obstacle_pushin_edge_material = material;
688 return debug_navigation_avoidance_static_obstacle_pushin_edge_material;
689 }
690
691 Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushout_edge_material() {
692 if (debug_navigation_avoidance_static_obstacle_pushout_edge_material.is_valid()) {
693 return debug_navigation_avoidance_static_obstacle_pushout_edge_material;
694 }
695
696 Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
697 material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
698 material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
699 ///material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
700 //material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
701 material->set_albedo(debug_navigation_avoidance_static_obstacle_pushout_edge_color);
702 //material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);
703 material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
704
705 debug_navigation_avoidance_static_obstacle_pushout_edge_material = material;
706 return debug_navigation_avoidance_static_obstacle_pushout_edge_material;
707 }
708
709 void NavigationServer3D::set_debug_navigation_edge_connection_color(const Color &p_color) {
710 debug_navigation_edge_connection_color = p_color;
711 if (debug_navigation_edge_connections_material.is_valid()) {
712 debug_navigation_edge_connections_material->set_albedo(debug_navigation_edge_connection_color);
713 }
714 }
715
716 Color NavigationServer3D::get_debug_navigation_edge_connection_color() const {
717 return debug_navigation_edge_connection_color;
718 }
719
720 void NavigationServer3D::set_debug_navigation_geometry_edge_color(const Color &p_color) {
721 debug_navigation_geometry_edge_color = p_color;
722 if (debug_navigation_geometry_edge_material.is_valid()) {
723 debug_navigation_geometry_edge_material->set_albedo(debug_navigation_geometry_edge_color);
724 }
725 }
726
727 Color NavigationServer3D::get_debug_navigation_geometry_edge_color() const {
728 return debug_navigation_geometry_edge_color;
729 }
730
731 void NavigationServer3D::set_debug_navigation_geometry_face_color(const Color &p_color) {
732 debug_navigation_geometry_face_color = p_color;
733 if (debug_navigation_geometry_face_material.is_valid()) {
734 debug_navigation_geometry_face_material->set_albedo(debug_navigation_geometry_face_color);
735 }
736 }
737
738 Color NavigationServer3D::get_debug_navigation_geometry_face_color() const {
739 return debug_navigation_geometry_face_color;
740 }
741
742 void NavigationServer3D::set_debug_navigation_geometry_edge_disabled_color(const Color &p_color) {
743 debug_navigation_geometry_edge_disabled_color = p_color;
744 if (debug_navigation_geometry_edge_disabled_material.is_valid()) {
745 debug_navigation_geometry_edge_disabled_material->set_albedo(debug_navigation_geometry_edge_disabled_color);
746 }
747 }
748
749 Color NavigationServer3D::get_debug_navigation_geometry_edge_disabled_color() const {
750 return debug_navigation_geometry_edge_disabled_color;
751 }
752
753 void NavigationServer3D::set_debug_navigation_geometry_face_disabled_color(const Color &p_color) {
754 debug_navigation_geometry_face_disabled_color = p_color;
755 if (debug_navigation_geometry_face_disabled_material.is_valid()) {
756 debug_navigation_geometry_face_disabled_material->set_albedo(debug_navigation_geometry_face_disabled_color);
757 }
758 }
759
760 Color NavigationServer3D::get_debug_navigation_geometry_face_disabled_color() const {
761 return debug_navigation_geometry_face_disabled_color;
762 }
763
764 void NavigationServer3D::set_debug_navigation_link_connection_color(const Color &p_color) {
765 debug_navigation_link_connection_color = p_color;
766 if (debug_navigation_link_connections_material.is_valid()) {
767 debug_navigation_link_connections_material->set_albedo(debug_navigation_link_connection_color);
768 }
769 }
770
771 Color NavigationServer3D::get_debug_navigation_link_connection_color() const {
772 return debug_navigation_link_connection_color;
773 }
774
775 void NavigationServer3D::set_debug_navigation_link_connection_disabled_color(const Color &p_color) {
776 debug_navigation_link_connection_disabled_color = p_color;
777 if (debug_navigation_link_connections_disabled_material.is_valid()) {
778 debug_navigation_link_connections_disabled_material->set_albedo(debug_navigation_link_connection_disabled_color);
779 }
780 }
781
782 Color NavigationServer3D::get_debug_navigation_link_connection_disabled_color() const {
783 return debug_navigation_link_connection_disabled_color;
784 }
785
786 void NavigationServer3D::set_debug_navigation_agent_path_point_size(real_t p_point_size) {
787 debug_navigation_agent_path_point_size = MAX(0.1, p_point_size);
788 if (debug_navigation_agent_path_point_material.is_valid()) {
789 debug_navigation_agent_path_point_material->set_point_size(debug_navigation_agent_path_point_size);
790 }
791 }
792
793 real_t NavigationServer3D::get_debug_navigation_agent_path_point_size() const {
794 return debug_navigation_agent_path_point_size;
795 }
796
797 void NavigationServer3D::set_debug_navigation_agent_path_color(const Color &p_color) {
798 debug_navigation_agent_path_color = p_color;
799 if (debug_navigation_agent_path_line_material.is_valid()) {
800 debug_navigation_agent_path_line_material->set_albedo(debug_navigation_agent_path_color);
801 }
802 if (debug_navigation_agent_path_point_material.is_valid()) {
803 debug_navigation_agent_path_point_material->set_albedo(debug_navigation_agent_path_color);
804 }
805 }
806
807 Color NavigationServer3D::get_debug_navigation_agent_path_color() const {
808 return debug_navigation_agent_path_color;
809 }
810
811 void NavigationServer3D::set_debug_navigation_enable_edge_connections(const bool p_value) {
812 debug_navigation_enable_edge_connections = p_value;
813 navigation_debug_dirty = true;
814 callable_mp(this, &NavigationServer3D::_emit_navigation_debug_changed_signal).call_deferred();
815 }
816
817 bool NavigationServer3D::get_debug_navigation_enable_edge_connections() const {
818 return debug_navigation_enable_edge_connections;
819 }
820
821 void NavigationServer3D::set_debug_navigation_enable_edge_connections_xray(const bool p_value) {
822 debug_navigation_enable_edge_connections_xray = p_value;
823 if (debug_navigation_edge_connections_material.is_valid()) {
824 debug_navigation_edge_connections_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_edge_connections_xray);
825 }
826 }
827
828 bool NavigationServer3D::get_debug_navigation_enable_edge_connections_xray() const {
829 return debug_navigation_enable_edge_connections_xray;
830 }
831
832 void NavigationServer3D::set_debug_navigation_enable_edge_lines(const bool p_value) {
833 debug_navigation_enable_edge_lines = p_value;
834 navigation_debug_dirty = true;
835 callable_mp(this, &NavigationServer3D::_emit_navigation_debug_changed_signal).call_deferred();
836 }
837
838 bool NavigationServer3D::get_debug_navigation_enable_edge_lines() const {
839 return debug_navigation_enable_edge_lines;
840 }
841
842 void NavigationServer3D::set_debug_navigation_enable_edge_lines_xray(const bool p_value) {
843 debug_navigation_enable_edge_lines_xray = p_value;
844 if (debug_navigation_geometry_edge_material.is_valid()) {
845 debug_navigation_geometry_edge_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_edge_lines_xray);
846 }
847 }
848
849 bool NavigationServer3D::get_debug_navigation_enable_edge_lines_xray() const {
850 return debug_navigation_enable_edge_lines_xray;
851 }
852
853 void NavigationServer3D::set_debug_navigation_enable_geometry_face_random_color(const bool p_value) {
854 debug_navigation_enable_geometry_face_random_color = p_value;
855 navigation_debug_dirty = true;
856 callable_mp(this, &NavigationServer3D::_emit_navigation_debug_changed_signal).call_deferred();
857 }
858
859 bool NavigationServer3D::get_debug_navigation_enable_geometry_face_random_color() const {
860 return debug_navigation_enable_geometry_face_random_color;
861 }
862
863 void NavigationServer3D::set_debug_navigation_enable_link_connections(const bool p_value) {
864 debug_navigation_enable_link_connections = p_value;
865 navigation_debug_dirty = true;
866 callable_mp(this, &NavigationServer3D::_emit_navigation_debug_changed_signal).call_deferred();
867 }
868
869 bool NavigationServer3D::get_debug_navigation_enable_link_connections() const {
870 return debug_navigation_enable_link_connections;
871 }
872
873 void NavigationServer3D::set_debug_navigation_enable_link_connections_xray(const bool p_value) {
874 debug_navigation_enable_link_connections_xray = p_value;
875 if (debug_navigation_link_connections_material.is_valid()) {
876 debug_navigation_link_connections_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_link_connections_xray);
877 }
878 }
879
880 bool NavigationServer3D::get_debug_navigation_enable_link_connections_xray() const {
881 return debug_navigation_enable_link_connections_xray;
882 }
883
884 void NavigationServer3D::set_debug_navigation_avoidance_enable_agents_radius(const bool p_value) {
885 debug_navigation_avoidance_enable_agents_radius = p_value;
886 avoidance_debug_dirty = true;
887 callable_mp(this, &NavigationServer3D::_emit_avoidance_debug_changed_signal).call_deferred();
888 }
889
890 bool NavigationServer3D::get_debug_navigation_avoidance_enable_agents_radius() const {
891 return debug_navigation_avoidance_enable_agents_radius;
892 }
893
894 void NavigationServer3D::set_debug_navigation_avoidance_enable_obstacles_radius(const bool p_value) {
895 debug_navigation_avoidance_enable_obstacles_radius = p_value;
896 avoidance_debug_dirty = true;
897 callable_mp(this, &NavigationServer3D::_emit_avoidance_debug_changed_signal).call_deferred();
898 }
899
900 bool NavigationServer3D::get_debug_navigation_avoidance_enable_obstacles_radius() const {
901 return debug_navigation_avoidance_enable_obstacles_radius;
902 }
903
904 void NavigationServer3D::set_debug_navigation_avoidance_enable_obstacles_static(const bool p_value) {
905 debug_navigation_avoidance_enable_obstacles_static = p_value;
906 avoidance_debug_dirty = true;
907 callable_mp(this, &NavigationServer3D::_emit_avoidance_debug_changed_signal).call_deferred();
908 }
909
910 bool NavigationServer3D::get_debug_navigation_avoidance_enable_obstacles_static() const {
911 return debug_navigation_avoidance_enable_obstacles_static;
912 }
913
914 void NavigationServer3D::set_debug_navigation_avoidance_agents_radius_color(const Color &p_color) {
915 debug_navigation_avoidance_agents_radius_color = p_color;
916 if (debug_navigation_avoidance_agents_radius_material.is_valid()) {
917 debug_navigation_avoidance_agents_radius_material->set_albedo(debug_navigation_avoidance_agents_radius_color);
918 }
919 }
920
921 Color NavigationServer3D::get_debug_navigation_avoidance_agents_radius_color() const {
922 return debug_navigation_avoidance_agents_radius_color;
923 }
924
925 void NavigationServer3D::set_debug_navigation_avoidance_obstacles_radius_color(const Color &p_color) {
926 debug_navigation_avoidance_obstacles_radius_color = p_color;
927 if (debug_navigation_avoidance_obstacles_radius_material.is_valid()) {
928 debug_navigation_avoidance_obstacles_radius_material->set_albedo(debug_navigation_avoidance_obstacles_radius_color);
929 }
930 }
931
932 Color NavigationServer3D::get_debug_navigation_avoidance_obstacles_radius_color() const {
933 return debug_navigation_avoidance_obstacles_radius_color;
934 }
935
936 void NavigationServer3D::set_debug_navigation_avoidance_static_obstacle_pushin_face_color(const Color &p_color) {
937 debug_navigation_avoidance_static_obstacle_pushin_face_color = p_color;
938 if (debug_navigation_avoidance_static_obstacle_pushin_face_material.is_valid()) {
939 debug_navigation_avoidance_static_obstacle_pushin_face_material->set_albedo(debug_navigation_avoidance_static_obstacle_pushin_face_color);
940 }
941 }
942
943 Color NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushin_face_color() const {
944 return debug_navigation_avoidance_static_obstacle_pushin_face_color;
945 }
946
947 void NavigationServer3D::set_debug_navigation_avoidance_static_obstacle_pushout_face_color(const Color &p_color) {
948 debug_navigation_avoidance_static_obstacle_pushout_face_color = p_color;
949 if (debug_navigation_avoidance_static_obstacle_pushout_face_material.is_valid()) {
950 debug_navigation_avoidance_static_obstacle_pushout_face_material->set_albedo(debug_navigation_avoidance_static_obstacle_pushout_face_color);
951 }
952 }
953
954 Color NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushout_face_color() const {
955 return debug_navigation_avoidance_static_obstacle_pushout_face_color;
956 }
957
958 void NavigationServer3D::set_debug_navigation_avoidance_static_obstacle_pushin_edge_color(const Color &p_color) {
959 debug_navigation_avoidance_static_obstacle_pushin_edge_color = p_color;
960 if (debug_navigation_avoidance_static_obstacle_pushin_edge_material.is_valid()) {
961 debug_navigation_avoidance_static_obstacle_pushin_edge_material->set_albedo(debug_navigation_avoidance_static_obstacle_pushin_edge_color);
962 }
963 }
964
965 Color NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushin_edge_color() const {
966 return debug_navigation_avoidance_static_obstacle_pushin_edge_color;
967 }
968
969 void NavigationServer3D::set_debug_navigation_avoidance_static_obstacle_pushout_edge_color(const Color &p_color) {
970 debug_navigation_avoidance_static_obstacle_pushout_edge_color = p_color;
971 if (debug_navigation_avoidance_static_obstacle_pushout_edge_material.is_valid()) {
972 debug_navigation_avoidance_static_obstacle_pushout_edge_material->set_albedo(debug_navigation_avoidance_static_obstacle_pushout_edge_color);
973 }
974 }
975
976 Color NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushout_edge_color() const {
977 return debug_navigation_avoidance_static_obstacle_pushout_edge_color;
978 }
979
980 void NavigationServer3D::set_debug_navigation_enable_agent_paths(const bool p_value) {
981 if (debug_navigation_enable_agent_paths != p_value) {
982 debug_dirty = true;
983 }
984
985 debug_navigation_enable_agent_paths = p_value;
986
987 if (debug_dirty) {
988 callable_mp(this, &NavigationServer3D::_emit_navigation_debug_changed_signal).call_deferred();
989 }
990 }
991
992 bool NavigationServer3D::get_debug_navigation_enable_agent_paths() const {
993 return debug_navigation_enable_agent_paths;
994 }
995
996 void NavigationServer3D::set_debug_navigation_enable_agent_paths_xray(const bool p_value) {
997 debug_navigation_enable_agent_paths_xray = p_value;
998 if (debug_navigation_agent_path_line_material.is_valid()) {
999 debug_navigation_agent_path_line_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_agent_paths_xray);
1000 }
1001 if (debug_navigation_agent_path_point_material.is_valid()) {
1002 debug_navigation_agent_path_point_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_agent_paths_xray);
1003 }
1004 }
1005
1006 bool NavigationServer3D::get_debug_navigation_enable_agent_paths_xray() const {
1007 return debug_navigation_enable_agent_paths_xray;
1008 }
1009
1010 void NavigationServer3D::set_debug_navigation_enabled(bool p_enabled) {
1011 debug_navigation_enabled = p_enabled;
1012 navigation_debug_dirty = true;
1013 callable_mp(this, &NavigationServer3D::_emit_navigation_debug_changed_signal).call_deferred();
1014 }
1015
1016 bool NavigationServer3D::get_debug_navigation_enabled() const {
1017 return debug_navigation_enabled;
1018 }
1019
1020 void NavigationServer3D::set_debug_avoidance_enabled(bool p_enabled) {
1021 debug_avoidance_enabled = p_enabled;
1022 avoidance_debug_dirty = true;
1023 callable_mp(this, &NavigationServer3D::_emit_avoidance_debug_changed_signal).call_deferred();
1024 }
1025
1026 bool NavigationServer3D::get_debug_avoidance_enabled() const {
1027 return debug_avoidance_enabled;
1028 }
1029
1030 #endif // DEBUG_ENABLED
1031
1032 ///////////////////////////////////////////////////////
1033
1034 static NavigationServer3D *navigation_server_3d = nullptr;
1035
1036 void NavigationServer3DManager::initialize_server() {
1037 ERR_FAIL_COND(navigation_server_3d != nullptr);
1038
1039 // Init 3D Navigation Server.
1040 navigation_server_3d = NavigationServer3DManager::get_singleton()->new_server(
1041 GLOBAL_GET(NavigationServer3DManager::setting_property_name));
1042 if (!navigation_server_3d) {
1043 // Navigation server not found, use the default.
1044 navigation_server_3d = NavigationServer3DManager::get_singleton()->new_default_server();
1045 }
1046
1047 // Fall back to dummy if no default server has been registered.
1048 if (!navigation_server_3d) {
1049 WARN_VERBOSE("Failed to initialize NavigationServer3D. Fall back to dummy server.");
1050 navigation_server_3d = memnew(NavigationServer3DDummy);
1051 }
1052
1053 // Should be impossible, but make sure it's not null.
1054 ERR_FAIL_NULL_MSG(navigation_server_3d, "Failed to initialize NavigationServer3D.");
1055 navigation_server_3d->init();
1056 }
1057
1058 void NavigationServer3DManager::finalize_server() {
1059 ERR_FAIL_NULL(navigation_server_3d);
1060 navigation_server_3d->finish();
1061 memdelete(navigation_server_3d);
1062 navigation_server_3d = nullptr;
1063 }
1064
1065 const String NavigationServer3DManager::setting_property_name(PNAME("navigation/3d/navigation_engine"));
1066
1067 void NavigationServer3DManager::on_servers_changed() {
1068 String navigation_servers_enum_str("DEFAULT");
1069 for (int i = get_servers_count() - 1; 0 <= i; --i) {
1070 navigation_servers_enum_str += "," + get_server_name(i);
1071 }
1072 ProjectSettings::get_singleton()->set_custom_property_info(PropertyInfo(Variant::STRING, setting_property_name, PROPERTY_HINT_ENUM, navigation_servers_enum_str));
1073 ProjectSettings::get_singleton()->set_restart_if_changed(setting_property_name, true);
1074 ProjectSettings::get_singleton()->set_as_basic(setting_property_name, true);
1075 }
1076
1077 void NavigationServer3DManager::_bind_methods() {
1078 ClassDB::bind_method(D_METHOD("register_server", "name", "create_callback"), &NavigationServer3DManager::register_server);
1079 ClassDB::bind_method(D_METHOD("set_default_server", "name", "priority"), &NavigationServer3DManager::set_default_server);
1080 }
1081
1082 NavigationServer3DManager *NavigationServer3DManager::get_singleton() {
1083 return singleton;
1084 }
1085
1086 void NavigationServer3DManager::register_server(const String &p_name, const Callable &p_create_callback) {
1087 ERR_FAIL_COND(find_server_id(p_name) != -1);
1088 navigation_servers.push_back(ClassInfo(p_name, p_create_callback));
1089 on_servers_changed();
1090 }
1091
1092 void NavigationServer3DManager::set_default_server(const String &p_name, int p_priority) {
1093 const int id = find_server_id(p_name);
1094 ERR_FAIL_COND(id == -1); // Not found
1095 if (default_server_priority < p_priority) {
1096 default_server_id = id;
1097 default_server_priority = p_priority;
1098 }
1099 }
1100
1101 int NavigationServer3DManager::find_server_id(const String &p_name) {
1102 for (int i = navigation_servers.size() - 1; 0 <= i; --i) {
1103 if (p_name == navigation_servers[i].name) {
1104 return i;
1105 }
1106 }
1107 return -1;
1108 }
1109
1110 int NavigationServer3DManager::get_servers_count() {
1111 return navigation_servers.size();
1112 }
1113
1114 String NavigationServer3DManager::get_server_name(int p_id) {
1115 ERR_FAIL_INDEX_V(p_id, get_servers_count(), "");
1116 return navigation_servers[p_id].name;
1117 }
1118
1119 NavigationServer3D *NavigationServer3DManager::new_default_server() {
1120 if (default_server_id == -1) {
1121 return nullptr;
1122 }
1123 Variant ret;
1124 Callable::CallError ce;
1125 navigation_servers[default_server_id].create_callback.callp(nullptr, 0, ret, ce);
1126 ERR_FAIL_COND_V(ce.error != Callable::CallError::CALL_OK, nullptr);
1127 return Object::cast_to<NavigationServer3D>(ret.get_validated_object());
1128 }
1129
1130 NavigationServer3D *NavigationServer3DManager::new_server(const String &p_name) {
1131 int id = find_server_id(p_name);
1132 if (id == -1) {
1133 return nullptr;
1134 } else {
1135 Variant ret;
1136 Callable::CallError ce;
1137 navigation_servers[id].create_callback.callp(nullptr, 0, ret, ce);
1138 ERR_FAIL_COND_V(ce.error != Callable::CallError::CALL_OK, nullptr);
1139 return Object::cast_to<NavigationServer3D>(ret.get_validated_object());
1140 }
1141 }
1142
1143 NavigationServer3D *NavigationServer3DManager::create_dummy_server_callback() {
1144 return memnew(NavigationServer3DDummy);
1145 }
1146
1147 NavigationServer3DManager::NavigationServer3DManager() {
1148 }
1149
1150 NavigationServer3DManager::~NavigationServer3DManager() {
1151 }
1152
1153 void NavigationServer3DManager::initialize_server_manager() {
1154 ERR_FAIL_COND(singleton != nullptr);
1155 singleton = memnew(NavigationServer3DManager);
1156 }
1157
1158 void NavigationServer3DManager::finalize_server_manager() {
1159 ERR_FAIL_NULL(singleton);
1160 memdelete(singleton);
1161 }