Path: blob/master/servers/navigation_3d/navigation_server_3d.cpp
11322 views
/**************************************************************************/1/* navigation_server_3d.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "navigation_server_3d.h"31#include "navigation_server_3d.compat.inc"3233#include "core/config/project_settings.h"34#include "scene/main/node.h"35#include "servers/navigation_3d/navigation_server_3d_dummy.h"3637NavigationServer3D *NavigationServer3D::singleton = nullptr;3839RWLock NavigationServer3D::geometry_parser_rwlock;40RID_Owner<NavMeshGeometryParser3D> NavigationServer3D::geometry_parser_owner;41LocalVector<NavMeshGeometryParser3D *> NavigationServer3D::generator_parsers;4243void NavigationServer3D::_bind_methods() {44ClassDB::bind_method(D_METHOD("get_maps"), &NavigationServer3D::get_maps);4546ClassDB::bind_method(D_METHOD("map_create"), &NavigationServer3D::map_create);47ClassDB::bind_method(D_METHOD("map_set_active", "map", "active"), &NavigationServer3D::map_set_active);48ClassDB::bind_method(D_METHOD("map_is_active", "map"), &NavigationServer3D::map_is_active);49ClassDB::bind_method(D_METHOD("map_set_up", "map", "up"), &NavigationServer3D::map_set_up);50ClassDB::bind_method(D_METHOD("map_get_up", "map"), &NavigationServer3D::map_get_up);51ClassDB::bind_method(D_METHOD("map_set_cell_size", "map", "cell_size"), &NavigationServer3D::map_set_cell_size);52ClassDB::bind_method(D_METHOD("map_get_cell_size", "map"), &NavigationServer3D::map_get_cell_size);53ClassDB::bind_method(D_METHOD("map_set_cell_height", "map", "cell_height"), &NavigationServer3D::map_set_cell_height);54ClassDB::bind_method(D_METHOD("map_get_cell_height", "map"), &NavigationServer3D::map_get_cell_height);55ClassDB::bind_method(D_METHOD("map_set_merge_rasterizer_cell_scale", "map", "scale"), &NavigationServer3D::map_set_merge_rasterizer_cell_scale);56ClassDB::bind_method(D_METHOD("map_get_merge_rasterizer_cell_scale", "map"), &NavigationServer3D::map_get_merge_rasterizer_cell_scale);57ClassDB::bind_method(D_METHOD("map_set_use_edge_connections", "map", "enabled"), &NavigationServer3D::map_set_use_edge_connections);58ClassDB::bind_method(D_METHOD("map_get_use_edge_connections", "map"), &NavigationServer3D::map_get_use_edge_connections);59ClassDB::bind_method(D_METHOD("map_set_edge_connection_margin", "map", "margin"), &NavigationServer3D::map_set_edge_connection_margin);60ClassDB::bind_method(D_METHOD("map_get_edge_connection_margin", "map"), &NavigationServer3D::map_get_edge_connection_margin);61ClassDB::bind_method(D_METHOD("map_set_link_connection_radius", "map", "radius"), &NavigationServer3D::map_set_link_connection_radius);62ClassDB::bind_method(D_METHOD("map_get_link_connection_radius", "map"), &NavigationServer3D::map_get_link_connection_radius);63ClassDB::bind_method(D_METHOD("map_get_path", "map", "origin", "destination", "optimize", "navigation_layers"), &NavigationServer3D::map_get_path, DEFVAL(1));64ClassDB::bind_method(D_METHOD("map_get_closest_point_to_segment", "map", "start", "end", "use_collision"), &NavigationServer3D::map_get_closest_point_to_segment, DEFVAL(false));65ClassDB::bind_method(D_METHOD("map_get_closest_point", "map", "to_point"), &NavigationServer3D::map_get_closest_point);66ClassDB::bind_method(D_METHOD("map_get_closest_point_normal", "map", "to_point"), &NavigationServer3D::map_get_closest_point_normal);67ClassDB::bind_method(D_METHOD("map_get_closest_point_owner", "map", "to_point"), &NavigationServer3D::map_get_closest_point_owner);6869ClassDB::bind_method(D_METHOD("map_get_links", "map"), &NavigationServer3D::map_get_links);70ClassDB::bind_method(D_METHOD("map_get_regions", "map"), &NavigationServer3D::map_get_regions);71ClassDB::bind_method(D_METHOD("map_get_agents", "map"), &NavigationServer3D::map_get_agents);72ClassDB::bind_method(D_METHOD("map_get_obstacles", "map"), &NavigationServer3D::map_get_obstacles);7374ClassDB::bind_method(D_METHOD("map_force_update", "map"), &NavigationServer3D::map_force_update);75ClassDB::bind_method(D_METHOD("map_get_iteration_id", "map"), &NavigationServer3D::map_get_iteration_id);76ClassDB::bind_method(D_METHOD("map_set_use_async_iterations", "map", "enabled"), &NavigationServer3D::map_set_use_async_iterations);77ClassDB::bind_method(D_METHOD("map_get_use_async_iterations", "map"), &NavigationServer3D::map_get_use_async_iterations);7879ClassDB::bind_method(D_METHOD("map_get_random_point", "map", "navigation_layers", "uniformly"), &NavigationServer3D::map_get_random_point);8081ClassDB::bind_method(D_METHOD("query_path", "parameters", "result", "callback"), &NavigationServer3D::query_path, DEFVAL(Callable()));8283ClassDB::bind_method(D_METHOD("region_create"), &NavigationServer3D::region_create);84ClassDB::bind_method(D_METHOD("region_get_iteration_id", "region"), &NavigationServer3D::region_get_iteration_id);85ClassDB::bind_method(D_METHOD("region_set_use_async_iterations", "region", "enabled"), &NavigationServer3D::region_set_use_async_iterations);86ClassDB::bind_method(D_METHOD("region_get_use_async_iterations", "region"), &NavigationServer3D::region_get_use_async_iterations);87ClassDB::bind_method(D_METHOD("region_set_enabled", "region", "enabled"), &NavigationServer3D::region_set_enabled);88ClassDB::bind_method(D_METHOD("region_get_enabled", "region"), &NavigationServer3D::region_get_enabled);89ClassDB::bind_method(D_METHOD("region_set_use_edge_connections", "region", "enabled"), &NavigationServer3D::region_set_use_edge_connections);90ClassDB::bind_method(D_METHOD("region_get_use_edge_connections", "region"), &NavigationServer3D::region_get_use_edge_connections);91ClassDB::bind_method(D_METHOD("region_set_enter_cost", "region", "enter_cost"), &NavigationServer3D::region_set_enter_cost);92ClassDB::bind_method(D_METHOD("region_get_enter_cost", "region"), &NavigationServer3D::region_get_enter_cost);93ClassDB::bind_method(D_METHOD("region_set_travel_cost", "region", "travel_cost"), &NavigationServer3D::region_set_travel_cost);94ClassDB::bind_method(D_METHOD("region_get_travel_cost", "region"), &NavigationServer3D::region_get_travel_cost);95ClassDB::bind_method(D_METHOD("region_set_owner_id", "region", "owner_id"), &NavigationServer3D::region_set_owner_id);96ClassDB::bind_method(D_METHOD("region_get_owner_id", "region"), &NavigationServer3D::region_get_owner_id);97ClassDB::bind_method(D_METHOD("region_owns_point", "region", "point"), &NavigationServer3D::region_owns_point);98ClassDB::bind_method(D_METHOD("region_set_map", "region", "map"), &NavigationServer3D::region_set_map);99ClassDB::bind_method(D_METHOD("region_get_map", "region"), &NavigationServer3D::region_get_map);100ClassDB::bind_method(D_METHOD("region_set_navigation_layers", "region", "navigation_layers"), &NavigationServer3D::region_set_navigation_layers);101ClassDB::bind_method(D_METHOD("region_get_navigation_layers", "region"), &NavigationServer3D::region_get_navigation_layers);102ClassDB::bind_method(D_METHOD("region_set_transform", "region", "transform"), &NavigationServer3D::region_set_transform);103ClassDB::bind_method(D_METHOD("region_get_transform", "region"), &NavigationServer3D::region_get_transform);104ClassDB::bind_method(D_METHOD("region_set_navigation_mesh", "region", "navigation_mesh"), &NavigationServer3D::region_set_navigation_mesh);105#ifndef DISABLE_DEPRECATED106ClassDB::bind_method(D_METHOD("region_bake_navigation_mesh", "navigation_mesh", "root_node"), &NavigationServer3D::region_bake_navigation_mesh);107#endif // DISABLE_DEPRECATED108ClassDB::bind_method(D_METHOD("region_get_connections_count", "region"), &NavigationServer3D::region_get_connections_count);109ClassDB::bind_method(D_METHOD("region_get_connection_pathway_start", "region", "connection"), &NavigationServer3D::region_get_connection_pathway_start);110ClassDB::bind_method(D_METHOD("region_get_connection_pathway_end", "region", "connection"), &NavigationServer3D::region_get_connection_pathway_end);111ClassDB::bind_method(D_METHOD("region_get_closest_point_to_segment", "region", "start", "end", "use_collision"), &NavigationServer3D::region_get_closest_point_to_segment, DEFVAL(false));112ClassDB::bind_method(D_METHOD("region_get_closest_point", "region", "to_point"), &NavigationServer3D::region_get_closest_point);113ClassDB::bind_method(D_METHOD("region_get_closest_point_normal", "region", "to_point"), &NavigationServer3D::region_get_closest_point_normal);114ClassDB::bind_method(D_METHOD("region_get_random_point", "region", "navigation_layers", "uniformly"), &NavigationServer3D::region_get_random_point);115ClassDB::bind_method(D_METHOD("region_get_bounds", "region"), &NavigationServer3D::region_get_bounds);116117ClassDB::bind_method(D_METHOD("link_create"), &NavigationServer3D::link_create);118ClassDB::bind_method(D_METHOD("link_get_iteration_id", "link"), &NavigationServer3D::link_get_iteration_id);119ClassDB::bind_method(D_METHOD("link_set_map", "link", "map"), &NavigationServer3D::link_set_map);120ClassDB::bind_method(D_METHOD("link_get_map", "link"), &NavigationServer3D::link_get_map);121ClassDB::bind_method(D_METHOD("link_set_enabled", "link", "enabled"), &NavigationServer3D::link_set_enabled);122ClassDB::bind_method(D_METHOD("link_get_enabled", "link"), &NavigationServer3D::link_get_enabled);123ClassDB::bind_method(D_METHOD("link_set_bidirectional", "link", "bidirectional"), &NavigationServer3D::link_set_bidirectional);124ClassDB::bind_method(D_METHOD("link_is_bidirectional", "link"), &NavigationServer3D::link_is_bidirectional);125ClassDB::bind_method(D_METHOD("link_set_navigation_layers", "link", "navigation_layers"), &NavigationServer3D::link_set_navigation_layers);126ClassDB::bind_method(D_METHOD("link_get_navigation_layers", "link"), &NavigationServer3D::link_get_navigation_layers);127ClassDB::bind_method(D_METHOD("link_set_start_position", "link", "position"), &NavigationServer3D::link_set_start_position);128ClassDB::bind_method(D_METHOD("link_get_start_position", "link"), &NavigationServer3D::link_get_start_position);129ClassDB::bind_method(D_METHOD("link_set_end_position", "link", "position"), &NavigationServer3D::link_set_end_position);130ClassDB::bind_method(D_METHOD("link_get_end_position", "link"), &NavigationServer3D::link_get_end_position);131ClassDB::bind_method(D_METHOD("link_set_enter_cost", "link", "enter_cost"), &NavigationServer3D::link_set_enter_cost);132ClassDB::bind_method(D_METHOD("link_get_enter_cost", "link"), &NavigationServer3D::link_get_enter_cost);133ClassDB::bind_method(D_METHOD("link_set_travel_cost", "link", "travel_cost"), &NavigationServer3D::link_set_travel_cost);134ClassDB::bind_method(D_METHOD("link_get_travel_cost", "link"), &NavigationServer3D::link_get_travel_cost);135ClassDB::bind_method(D_METHOD("link_set_owner_id", "link", "owner_id"), &NavigationServer3D::link_set_owner_id);136ClassDB::bind_method(D_METHOD("link_get_owner_id", "link"), &NavigationServer3D::link_get_owner_id);137138ClassDB::bind_method(D_METHOD("agent_create"), &NavigationServer3D::agent_create);139ClassDB::bind_method(D_METHOD("agent_set_avoidance_enabled", "agent", "enabled"), &NavigationServer3D::agent_set_avoidance_enabled);140ClassDB::bind_method(D_METHOD("agent_get_avoidance_enabled", "agent"), &NavigationServer3D::agent_get_avoidance_enabled);141ClassDB::bind_method(D_METHOD("agent_set_use_3d_avoidance", "agent", "enabled"), &NavigationServer3D::agent_set_use_3d_avoidance);142ClassDB::bind_method(D_METHOD("agent_get_use_3d_avoidance", "agent"), &NavigationServer3D::agent_get_use_3d_avoidance);143144ClassDB::bind_method(D_METHOD("agent_set_map", "agent", "map"), &NavigationServer3D::agent_set_map);145ClassDB::bind_method(D_METHOD("agent_get_map", "agent"), &NavigationServer3D::agent_get_map);146ClassDB::bind_method(D_METHOD("agent_set_paused", "agent", "paused"), &NavigationServer3D::agent_set_paused);147ClassDB::bind_method(D_METHOD("agent_get_paused", "agent"), &NavigationServer3D::agent_get_paused);148ClassDB::bind_method(D_METHOD("agent_set_neighbor_distance", "agent", "distance"), &NavigationServer3D::agent_set_neighbor_distance);149ClassDB::bind_method(D_METHOD("agent_get_neighbor_distance", "agent"), &NavigationServer3D::agent_get_neighbor_distance);150ClassDB::bind_method(D_METHOD("agent_set_max_neighbors", "agent", "count"), &NavigationServer3D::agent_set_max_neighbors);151ClassDB::bind_method(D_METHOD("agent_get_max_neighbors", "agent"), &NavigationServer3D::agent_get_max_neighbors);152ClassDB::bind_method(D_METHOD("agent_set_time_horizon_agents", "agent", "time_horizon"), &NavigationServer3D::agent_set_time_horizon_agents);153ClassDB::bind_method(D_METHOD("agent_get_time_horizon_agents", "agent"), &NavigationServer3D::agent_get_time_horizon_agents);154ClassDB::bind_method(D_METHOD("agent_set_time_horizon_obstacles", "agent", "time_horizon"), &NavigationServer3D::agent_set_time_horizon_obstacles);155ClassDB::bind_method(D_METHOD("agent_get_time_horizon_obstacles", "agent"), &NavigationServer3D::agent_get_time_horizon_obstacles);156ClassDB::bind_method(D_METHOD("agent_set_radius", "agent", "radius"), &NavigationServer3D::agent_set_radius);157ClassDB::bind_method(D_METHOD("agent_get_radius", "agent"), &NavigationServer3D::agent_get_radius);158ClassDB::bind_method(D_METHOD("agent_set_height", "agent", "height"), &NavigationServer3D::agent_set_height);159ClassDB::bind_method(D_METHOD("agent_get_height", "agent"), &NavigationServer3D::agent_get_height);160ClassDB::bind_method(D_METHOD("agent_set_max_speed", "agent", "max_speed"), &NavigationServer3D::agent_set_max_speed);161ClassDB::bind_method(D_METHOD("agent_get_max_speed", "agent"), &NavigationServer3D::agent_get_max_speed);162ClassDB::bind_method(D_METHOD("agent_set_velocity_forced", "agent", "velocity"), &NavigationServer3D::agent_set_velocity_forced);163ClassDB::bind_method(D_METHOD("agent_set_velocity", "agent", "velocity"), &NavigationServer3D::agent_set_velocity);164ClassDB::bind_method(D_METHOD("agent_get_velocity", "agent"), &NavigationServer3D::agent_get_velocity);165ClassDB::bind_method(D_METHOD("agent_set_position", "agent", "position"), &NavigationServer3D::agent_set_position);166ClassDB::bind_method(D_METHOD("agent_get_position", "agent"), &NavigationServer3D::agent_get_position);167ClassDB::bind_method(D_METHOD("agent_is_map_changed", "agent"), &NavigationServer3D::agent_is_map_changed);168ClassDB::bind_method(D_METHOD("agent_set_avoidance_callback", "agent", "callback"), &NavigationServer3D::agent_set_avoidance_callback);169ClassDB::bind_method(D_METHOD("agent_has_avoidance_callback", "agent"), &NavigationServer3D::agent_has_avoidance_callback);170ClassDB::bind_method(D_METHOD("agent_set_avoidance_layers", "agent", "layers"), &NavigationServer3D::agent_set_avoidance_layers);171ClassDB::bind_method(D_METHOD("agent_get_avoidance_layers", "agent"), &NavigationServer3D::agent_get_avoidance_layers);172ClassDB::bind_method(D_METHOD("agent_set_avoidance_mask", "agent", "mask"), &NavigationServer3D::agent_set_avoidance_mask);173ClassDB::bind_method(D_METHOD("agent_get_avoidance_mask", "agent"), &NavigationServer3D::agent_get_avoidance_mask);174ClassDB::bind_method(D_METHOD("agent_set_avoidance_priority", "agent", "priority"), &NavigationServer3D::agent_set_avoidance_priority);175ClassDB::bind_method(D_METHOD("agent_get_avoidance_priority", "agent"), &NavigationServer3D::agent_get_avoidance_priority);176177ClassDB::bind_method(D_METHOD("obstacle_create"), &NavigationServer3D::obstacle_create);178ClassDB::bind_method(D_METHOD("obstacle_set_avoidance_enabled", "obstacle", "enabled"), &NavigationServer3D::obstacle_set_avoidance_enabled);179ClassDB::bind_method(D_METHOD("obstacle_get_avoidance_enabled", "obstacle"), &NavigationServer3D::obstacle_get_avoidance_enabled);180ClassDB::bind_method(D_METHOD("obstacle_set_use_3d_avoidance", "obstacle", "enabled"), &NavigationServer3D::obstacle_set_use_3d_avoidance);181ClassDB::bind_method(D_METHOD("obstacle_get_use_3d_avoidance", "obstacle"), &NavigationServer3D::obstacle_get_use_3d_avoidance);182ClassDB::bind_method(D_METHOD("obstacle_set_map", "obstacle", "map"), &NavigationServer3D::obstacle_set_map);183ClassDB::bind_method(D_METHOD("obstacle_get_map", "obstacle"), &NavigationServer3D::obstacle_get_map);184ClassDB::bind_method(D_METHOD("obstacle_set_paused", "obstacle", "paused"), &NavigationServer3D::obstacle_set_paused);185ClassDB::bind_method(D_METHOD("obstacle_get_paused", "obstacle"), &NavigationServer3D::obstacle_get_paused);186ClassDB::bind_method(D_METHOD("obstacle_set_radius", "obstacle", "radius"), &NavigationServer3D::obstacle_set_radius);187ClassDB::bind_method(D_METHOD("obstacle_get_radius", "obstacle"), &NavigationServer3D::obstacle_get_radius);188ClassDB::bind_method(D_METHOD("obstacle_set_height", "obstacle", "height"), &NavigationServer3D::obstacle_set_height);189ClassDB::bind_method(D_METHOD("obstacle_get_height", "obstacle"), &NavigationServer3D::obstacle_get_height);190ClassDB::bind_method(D_METHOD("obstacle_set_velocity", "obstacle", "velocity"), &NavigationServer3D::obstacle_set_velocity);191ClassDB::bind_method(D_METHOD("obstacle_get_velocity", "obstacle"), &NavigationServer3D::obstacle_get_velocity);192ClassDB::bind_method(D_METHOD("obstacle_set_position", "obstacle", "position"), &NavigationServer3D::obstacle_set_position);193ClassDB::bind_method(D_METHOD("obstacle_get_position", "obstacle"), &NavigationServer3D::obstacle_get_position);194ClassDB::bind_method(D_METHOD("obstacle_set_vertices", "obstacle", "vertices"), &NavigationServer3D::obstacle_set_vertices);195ClassDB::bind_method(D_METHOD("obstacle_get_vertices", "obstacle"), &NavigationServer3D::obstacle_get_vertices);196ClassDB::bind_method(D_METHOD("obstacle_set_avoidance_layers", "obstacle", "layers"), &NavigationServer3D::obstacle_set_avoidance_layers);197ClassDB::bind_method(D_METHOD("obstacle_get_avoidance_layers", "obstacle"), &NavigationServer3D::obstacle_get_avoidance_layers);198199#ifndef _3D_DISABLED200ClassDB::bind_method(D_METHOD("parse_source_geometry_data", "navigation_mesh", "source_geometry_data", "root_node", "callback"), &NavigationServer3D::parse_source_geometry_data, DEFVAL(Callable()));201ClassDB::bind_method(D_METHOD("bake_from_source_geometry_data", "navigation_mesh", "source_geometry_data", "callback"), &NavigationServer3D::bake_from_source_geometry_data, DEFVAL(Callable()));202ClassDB::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()));203ClassDB::bind_method(D_METHOD("is_baking_navigation_mesh", "navigation_mesh"), &NavigationServer3D::is_baking_navigation_mesh);204#endif // _3D_DISABLED205206ClassDB::bind_method(D_METHOD("source_geometry_parser_create"), &NavigationServer3D::source_geometry_parser_create);207ClassDB::bind_method(D_METHOD("source_geometry_parser_set_callback", "parser", "callback"), &NavigationServer3D::source_geometry_parser_set_callback);208209ClassDB::bind_method(D_METHOD("simplify_path", "path", "epsilon"), &NavigationServer3D::simplify_path);210211ClassDB::bind_method(D_METHOD("free_rid", "rid"), &NavigationServer3D::free_rid);212213ClassDB::bind_method(D_METHOD("set_active", "active"), &NavigationServer3D::set_active);214215ClassDB::bind_method(D_METHOD("set_debug_enabled", "enabled"), &NavigationServer3D::set_debug_enabled);216ClassDB::bind_method(D_METHOD("get_debug_enabled"), &NavigationServer3D::get_debug_enabled);217218ADD_SIGNAL(MethodInfo("map_changed", PropertyInfo(Variant::RID, "map")));219220ADD_SIGNAL(MethodInfo("navigation_debug_changed"));221ADD_SIGNAL(MethodInfo("avoidance_debug_changed"));222223ClassDB::bind_method(D_METHOD("get_process_info", "process_info"), &NavigationServer3D::get_process_info);224225BIND_ENUM_CONSTANT(INFO_ACTIVE_MAPS);226BIND_ENUM_CONSTANT(INFO_REGION_COUNT);227BIND_ENUM_CONSTANT(INFO_AGENT_COUNT);228BIND_ENUM_CONSTANT(INFO_LINK_COUNT);229BIND_ENUM_CONSTANT(INFO_POLYGON_COUNT);230BIND_ENUM_CONSTANT(INFO_EDGE_COUNT);231BIND_ENUM_CONSTANT(INFO_EDGE_MERGE_COUNT);232BIND_ENUM_CONSTANT(INFO_EDGE_CONNECTION_COUNT);233BIND_ENUM_CONSTANT(INFO_EDGE_FREE_COUNT);234BIND_ENUM_CONSTANT(INFO_OBSTACLE_COUNT);235}236237NavigationServer3D *NavigationServer3D::get_singleton() {238return singleton;239}240241NavigationServer3D::NavigationServer3D() {242ERR_FAIL_COND(singleton != nullptr);243singleton = this;244245GLOBAL_DEF_BASIC(PropertyInfo(Variant::FLOAT, "navigation/3d/default_cell_size", PROPERTY_HINT_RANGE, NavigationDefaults3D::NAV_MESH_CELL_SIZE_HINT), NavigationDefaults3D::NAV_MESH_CELL_SIZE);246GLOBAL_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);247GLOBAL_DEF("navigation/3d/default_up", Vector3(0, 1, 0));248GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "navigation/3d/merge_rasterizer_cell_scale", PROPERTY_HINT_RANGE, "0.001,1,0.001,or_greater"), 1.0);249GLOBAL_DEF("navigation/3d/use_edge_connections", true);250GLOBAL_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);251GLOBAL_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);252253#ifdef DEBUG_ENABLED254#ifndef DISABLE_DEPRECATED255#define MOVE_PROJECT_SETTING_1(m_old_setting, m_new_setting) \256if (!ProjectSettings::get_singleton()->has_setting(m_new_setting) && ProjectSettings::get_singleton()->has_setting(m_old_setting)) { \257Variant value = GLOBAL_GET(m_old_setting); \258ProjectSettings::get_singleton()->set_setting(m_new_setting, value); \259ProjectSettings::get_singleton()->clear(m_old_setting); \260}261#define MOVE_PROJECT_SETTING_2(m_old_setting, m_new_setting_1, m_new_setting_2) \262if ((!ProjectSettings::get_singleton()->has_setting(m_new_setting_1) || !ProjectSettings::get_singleton()->has_setting(m_new_setting_2)) && \263ProjectSettings::get_singleton()->has_setting(m_old_setting)) { \264Variant value = GLOBAL_GET(m_old_setting); \265if (!ProjectSettings::get_singleton()->has_setting(m_new_setting_1)) { \266ProjectSettings::get_singleton()->set_setting(m_new_setting_1, value); \267} \268if (!ProjectSettings::get_singleton()->has_setting(m_new_setting_2)) { \269ProjectSettings::get_singleton()->set_setting(m_new_setting_2, value); \270} \271ProjectSettings::get_singleton()->clear(m_old_setting); \272}273MOVE_PROJECT_SETTING_2("debug/shapes/navigation/edge_connection_color", "debug/shapes/navigation/2d/edge_connection_color", "debug/shapes/navigation/3d/edge_connection_color");274MOVE_PROJECT_SETTING_2("debug/shapes/navigation/geometry_edge_color", "debug/shapes/navigation/2d/geometry_edge_color", "debug/shapes/navigation/3d/geometry_edge_color");275MOVE_PROJECT_SETTING_2("debug/shapes/navigation/geometry_face_color", "debug/shapes/navigation/2d/geometry_face_color", "debug/shapes/navigation/3d/geometry_face_color");276MOVE_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");277MOVE_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");278MOVE_PROJECT_SETTING_2("debug/shapes/navigation/link_connection_color", "debug/shapes/navigation/2d/link_connection_color", "debug/shapes/navigation/3d/link_connection_color");279MOVE_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");280MOVE_PROJECT_SETTING_2("debug/shapes/navigation/agent_path_color", "debug/shapes/navigation/2d/agent_path_color", "debug/shapes/navigation/3d/agent_path_color");281282MOVE_PROJECT_SETTING_2("debug/shapes/navigation/enable_edge_connections", "debug/shapes/navigation/2d/enable_edge_connections", "debug/shapes/navigation/3d/enable_edge_connections");283MOVE_PROJECT_SETTING_1("debug/shapes/navigation/enable_edge_connections_xray", "debug/shapes/navigation/3d/enable_edge_connections_xray");284MOVE_PROJECT_SETTING_2("debug/shapes/navigation/enable_edge_lines", "debug/shapes/navigation/2d/enable_edge_lines", "debug/shapes/navigation/3d/enable_edge_lines");285MOVE_PROJECT_SETTING_1("debug/shapes/navigation/enable_edge_lines_xray", "debug/shapes/navigation/3d/enable_edge_lines_xray");286MOVE_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");287MOVE_PROJECT_SETTING_2("debug/shapes/navigation/enable_link_connections", "debug/shapes/navigation/2d/enable_link_connections", "debug/shapes/navigation/3d/enable_link_connections");288MOVE_PROJECT_SETTING_1("debug/shapes/navigation/enable_link_connections_xray", "debug/shapes/navigation/3d/enable_link_connections_xray");289290MOVE_PROJECT_SETTING_2("debug/shapes/navigation/enable_agent_paths", "debug/shapes/navigation/2d/enable_agent_paths", "debug/shapes/navigation/3d/enable_agent_paths");291MOVE_PROJECT_SETTING_1("debug/shapes/navigation/enable_agent_paths_xray", "debug/shapes/navigation/3d/enable_agent_paths_xray");292MOVE_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");293294MOVE_PROJECT_SETTING_2("debug/shapes/avoidance/agents_radius_color", "debug/shapes/avoidance/2d/agents_radius_color", "debug/shapes/avoidance/3d/agents_radius_color");295MOVE_PROJECT_SETTING_2("debug/shapes/avoidance/obstacles_radius_color", "debug/shapes/avoidance/2d/obstacles_radius_color", "debug/shapes/avoidance/3d/obstacles_radius_color");296MOVE_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");297MOVE_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");298MOVE_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");299MOVE_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");300MOVE_PROJECT_SETTING_2("debug/shapes/avoidance/enable_agents_radius", "debug/shapes/avoidance/2d/enable_agents_radius", "debug/shapes/avoidance/3d/enable_agents_radius");301MOVE_PROJECT_SETTING_2("debug/shapes/avoidance/enable_obstacles_radius", "debug/shapes/avoidance/2d/enable_obstacles_radius", "debug/shapes/avoidance/2d/enable_obstacles_static");302MOVE_PROJECT_SETTING_2("debug/shapes/avoidance/enable_obstacles_radius", "debug/shapes/avoidance/3d/enable_obstacles_radius", "debug/shapes/avoidance/3d/enable_obstacles_static");303#undef MOVE_PROJECT_SETTING_1304#undef MOVE_PROJECT_SETTING_2305#endif // DISABLE_DEPRECATED306307debug_navigation_edge_connection_color = GLOBAL_DEF("debug/shapes/navigation/3d/edge_connection_color", Color(1.0, 0.0, 1.0, 1.0));308debug_navigation_geometry_edge_color = GLOBAL_DEF("debug/shapes/navigation/3d/geometry_edge_color", Color(0.5, 1.0, 1.0, 1.0));309debug_navigation_geometry_face_color = GLOBAL_DEF("debug/shapes/navigation/3d/geometry_face_color", Color(0.5, 1.0, 1.0, 0.4));310debug_navigation_geometry_edge_disabled_color = GLOBAL_DEF("debug/shapes/navigation/3d/geometry_edge_disabled_color", Color(0.5, 0.5, 0.5, 1.0));311debug_navigation_geometry_face_disabled_color = GLOBAL_DEF("debug/shapes/navigation/3d/geometry_face_disabled_color", Color(0.5, 0.5, 0.5, 0.4));312debug_navigation_link_connection_color = GLOBAL_DEF("debug/shapes/navigation/3d/link_connection_color", Color(1.0, 0.5, 1.0, 1.0));313debug_navigation_link_connection_disabled_color = GLOBAL_DEF("debug/shapes/navigation/3d/link_connection_disabled_color", Color(0.5, 0.5, 0.5, 1.0));314debug_navigation_agent_path_color = GLOBAL_DEF("debug/shapes/navigation/3d/agent_path_color", Color(1.0, 0.0, 0.0, 1.0));315316debug_navigation_enable_edge_connections = GLOBAL_DEF("debug/shapes/navigation/3d/enable_edge_connections", true);317debug_navigation_enable_edge_connections_xray = GLOBAL_DEF("debug/shapes/navigation/3d/enable_edge_connections_xray", true);318debug_navigation_enable_edge_lines = GLOBAL_DEF("debug/shapes/navigation/3d/enable_edge_lines", true);319debug_navigation_enable_edge_lines_xray = GLOBAL_DEF("debug/shapes/navigation/3d/enable_edge_lines_xray", true);320debug_navigation_enable_geometry_face_random_color = GLOBAL_DEF("debug/shapes/navigation/3d/enable_geometry_face_random_color", true);321debug_navigation_enable_link_connections = GLOBAL_DEF("debug/shapes/navigation/3d/enable_link_connections", true);322debug_navigation_enable_link_connections_xray = GLOBAL_DEF("debug/shapes/navigation/3d/enable_link_connections_xray", true);323324debug_navigation_enable_agent_paths = GLOBAL_DEF("debug/shapes/navigation/3d/enable_agent_paths", true);325debug_navigation_enable_agent_paths_xray = GLOBAL_DEF("debug/shapes/navigation/3d/enable_agent_paths_xray", true);326debug_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);327328debug_navigation_avoidance_agents_radius_color = GLOBAL_DEF("debug/shapes/avoidance/3d/agents_radius_color", Color(1.0, 1.0, 0.0, 0.25));329debug_navigation_avoidance_obstacles_radius_color = GLOBAL_DEF("debug/shapes/avoidance/3d/obstacles_radius_color", Color(1.0, 0.5, 0.0, 0.25));330debug_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));331debug_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));332debug_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));333debug_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));334debug_navigation_avoidance_enable_agents_radius = GLOBAL_DEF("debug/shapes/avoidance/3d/enable_agents_radius", true);335debug_navigation_avoidance_enable_obstacles_radius = GLOBAL_DEF("debug/shapes/avoidance/3d/enable_obstacles_radius", true);336debug_navigation_avoidance_enable_obstacles_static = GLOBAL_DEF("debug/shapes/avoidance/3d/enable_obstacles_static", true);337338if (Engine::get_singleton()->is_editor_hint()) {339// enable NavigationServer3D when in Editor or else navigation mesh edge connections are invisible340// on runtime tests SceneTree has "Visible Navigation" set and main iteration takes care of this341set_debug_enabled(true);342set_debug_navigation_enabled(true);343set_debug_avoidance_enabled(true);344}345#endif // DEBUG_ENABLED346}347348NavigationServer3D::~NavigationServer3D() {349singleton = nullptr;350351RWLockWrite write_lock(geometry_parser_rwlock);352for (NavMeshGeometryParser3D *parser : generator_parsers) {353geometry_parser_owner.free(parser->self);354}355generator_parsers.clear();356}357358RID NavigationServer3D::source_geometry_parser_create() {359RWLockWrite write_lock(geometry_parser_rwlock);360361RID rid = geometry_parser_owner.make_rid();362363NavMeshGeometryParser3D *parser = geometry_parser_owner.get_or_null(rid);364parser->self = rid;365366generator_parsers.push_back(parser);367368return rid;369}370371void NavigationServer3D::free_rid(RID p_rid) {372if (!geometry_parser_owner.owns(p_rid)) {373return;374}375RWLockWrite write_lock(geometry_parser_rwlock);376377NavMeshGeometryParser3D *parser = geometry_parser_owner.get_or_null(p_rid);378ERR_FAIL_NULL(parser);379380generator_parsers.erase(parser);381geometry_parser_owner.free(parser->self);382}383384void NavigationServer3D::source_geometry_parser_set_callback(RID p_parser, const Callable &p_callback) {385RWLockWrite write_lock(geometry_parser_rwlock);386387NavMeshGeometryParser3D *parser = geometry_parser_owner.get_or_null(p_parser);388ERR_FAIL_NULL(parser);389390parser->callback = p_callback;391}392393void NavigationServer3D::set_debug_enabled(bool p_enabled) {394#ifdef DEBUG_ENABLED395if (debug_enabled != p_enabled) {396debug_dirty = true;397}398399debug_enabled = p_enabled;400401if (debug_dirty) {402navigation_debug_dirty = true;403callable_mp(this, &NavigationServer3D::_emit_navigation_debug_changed_signal).call_deferred();404405avoidance_debug_dirty = true;406callable_mp(this, &NavigationServer3D::_emit_avoidance_debug_changed_signal).call_deferred();407}408#endif // DEBUG_ENABLED409}410411bool NavigationServer3D::get_debug_enabled() const {412return debug_enabled;413}414415#ifdef DEBUG_ENABLED416void NavigationServer3D::_emit_navigation_debug_changed_signal() {417if (navigation_debug_dirty) {418navigation_debug_dirty = false;419emit_signal(SNAME("navigation_debug_changed"));420}421}422423void NavigationServer3D::_emit_avoidance_debug_changed_signal() {424if (avoidance_debug_dirty) {425avoidance_debug_dirty = false;426emit_signal(SNAME("avoidance_debug_changed"));427}428}429#endif // DEBUG_ENABLED430431#ifdef DEBUG_ENABLED432Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_geometry_face_material() {433if (debug_navigation_geometry_face_material.is_valid()) {434return debug_navigation_geometry_face_material;435}436437bool enabled_geometry_face_random_color = get_debug_navigation_enable_geometry_face_random_color();438439Ref<StandardMaterial3D> face_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));440face_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);441face_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);442face_material->set_albedo(get_debug_navigation_geometry_face_color());443face_material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);444face_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);445if (enabled_geometry_face_random_color) {446face_material->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true);447face_material->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);448}449450debug_navigation_geometry_face_material = face_material;451452return debug_navigation_geometry_face_material;453}454455Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_geometry_edge_material() {456if (debug_navigation_geometry_edge_material.is_valid()) {457return debug_navigation_geometry_edge_material;458}459460bool enabled_edge_lines_xray = get_debug_navigation_enable_edge_lines_xray();461462Ref<StandardMaterial3D> line_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));463line_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);464line_material->set_albedo(get_debug_navigation_geometry_edge_color());465line_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);466if (enabled_edge_lines_xray) {467line_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);468}469470debug_navigation_geometry_edge_material = line_material;471472return debug_navigation_geometry_edge_material;473}474475Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_geometry_face_disabled_material() {476if (debug_navigation_geometry_face_disabled_material.is_valid()) {477return debug_navigation_geometry_face_disabled_material;478}479480Ref<StandardMaterial3D> face_disabled_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));481face_disabled_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);482face_disabled_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);483face_disabled_material->set_albedo(get_debug_navigation_geometry_face_disabled_color());484face_disabled_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);485486debug_navigation_geometry_face_disabled_material = face_disabled_material;487488return debug_navigation_geometry_face_disabled_material;489}490491Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_geometry_edge_disabled_material() {492if (debug_navigation_geometry_edge_disabled_material.is_valid()) {493return debug_navigation_geometry_edge_disabled_material;494}495496bool enabled_edge_lines_xray = get_debug_navigation_enable_edge_lines_xray();497498Ref<StandardMaterial3D> line_disabled_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));499line_disabled_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);500line_disabled_material->set_albedo(get_debug_navigation_geometry_edge_disabled_color());501line_disabled_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);502if (enabled_edge_lines_xray) {503line_disabled_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);504}505506debug_navigation_geometry_edge_disabled_material = line_disabled_material;507508return debug_navigation_geometry_edge_disabled_material;509}510511Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_edge_connections_material() {512if (debug_navigation_edge_connections_material.is_valid()) {513return debug_navigation_edge_connections_material;514}515516bool enabled_edge_connections_xray = get_debug_navigation_enable_edge_connections_xray();517518Ref<StandardMaterial3D> edge_connections_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));519edge_connections_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);520edge_connections_material->set_albedo(get_debug_navigation_edge_connection_color());521edge_connections_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);522if (enabled_edge_connections_xray) {523edge_connections_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);524}525edge_connections_material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);526527debug_navigation_edge_connections_material = edge_connections_material;528529return debug_navigation_edge_connections_material;530}531532Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_link_connections_material() {533if (debug_navigation_link_connections_material.is_valid()) {534return debug_navigation_link_connections_material;535}536537Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));538material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);539material->set_albedo(debug_navigation_link_connection_color);540material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);541if (debug_navigation_enable_link_connections_xray) {542material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);543}544material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);545546debug_navigation_link_connections_material = material;547return debug_navigation_link_connections_material;548}549550Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_link_connections_disabled_material() {551if (debug_navigation_link_connections_disabled_material.is_valid()) {552return debug_navigation_link_connections_disabled_material;553}554555Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));556material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);557material->set_albedo(debug_navigation_link_connection_disabled_color);558material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);559if (debug_navigation_enable_link_connections_xray) {560material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);561}562material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);563564debug_navigation_link_connections_disabled_material = material;565return debug_navigation_link_connections_disabled_material;566}567568Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_agent_path_line_material() {569if (debug_navigation_agent_path_line_material.is_valid()) {570return debug_navigation_agent_path_line_material;571}572573Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));574material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);575576material->set_albedo(debug_navigation_agent_path_color);577material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);578if (debug_navigation_enable_agent_paths_xray) {579material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);580}581material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);582583debug_navigation_agent_path_line_material = material;584return debug_navigation_agent_path_line_material;585}586587Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_agent_path_point_material() {588if (debug_navigation_agent_path_point_material.is_valid()) {589return debug_navigation_agent_path_point_material;590}591592Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));593material->set_albedo(debug_navigation_agent_path_color);594material->set_flag(StandardMaterial3D::FLAG_USE_POINT_SIZE, true);595material->set_point_size(debug_navigation_agent_path_point_size);596material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);597if (debug_navigation_enable_agent_paths_xray) {598material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);599}600material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MAX - 2);601602debug_navigation_agent_path_point_material = material;603return debug_navigation_agent_path_point_material;604}605606Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_agents_radius_material() {607if (debug_navigation_avoidance_agents_radius_material.is_valid()) {608return debug_navigation_avoidance_agents_radius_material;609}610611Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));612material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);613material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);614material->set_albedo(debug_navigation_avoidance_agents_radius_color);615material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);616617debug_navigation_avoidance_agents_radius_material = material;618return debug_navigation_avoidance_agents_radius_material;619}620621Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_obstacles_radius_material() {622if (debug_navigation_avoidance_obstacles_radius_material.is_valid()) {623return debug_navigation_avoidance_obstacles_radius_material;624}625626Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));627material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);628material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);629material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);630material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);631material->set_albedo(debug_navigation_avoidance_obstacles_radius_color);632material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);633634debug_navigation_avoidance_obstacles_radius_material = material;635return debug_navigation_avoidance_obstacles_radius_material;636}637638Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushin_face_material() {639if (debug_navigation_avoidance_static_obstacle_pushin_face_material.is_valid()) {640return debug_navigation_avoidance_static_obstacle_pushin_face_material;641}642643Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));644material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);645material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);646material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);647material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);648material->set_albedo(debug_navigation_avoidance_static_obstacle_pushin_face_color);649material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);650651debug_navigation_avoidance_static_obstacle_pushin_face_material = material;652return debug_navigation_avoidance_static_obstacle_pushin_face_material;653}654655Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushout_face_material() {656if (debug_navigation_avoidance_static_obstacle_pushout_face_material.is_valid()) {657return debug_navigation_avoidance_static_obstacle_pushout_face_material;658}659660Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));661material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);662material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);663material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);664material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);665material->set_albedo(debug_navigation_avoidance_static_obstacle_pushout_face_color);666material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);667668debug_navigation_avoidance_static_obstacle_pushout_face_material = material;669return debug_navigation_avoidance_static_obstacle_pushout_face_material;670}671672Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushin_edge_material() {673if (debug_navigation_avoidance_static_obstacle_pushin_edge_material.is_valid()) {674return debug_navigation_avoidance_static_obstacle_pushin_edge_material;675}676677Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));678material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);679material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);680//material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);681//material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);682material->set_albedo(debug_navigation_avoidance_static_obstacle_pushin_edge_color);683//material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);684material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);685686debug_navigation_avoidance_static_obstacle_pushin_edge_material = material;687return debug_navigation_avoidance_static_obstacle_pushin_edge_material;688}689690Ref<StandardMaterial3D> NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushout_edge_material() {691if (debug_navigation_avoidance_static_obstacle_pushout_edge_material.is_valid()) {692return debug_navigation_avoidance_static_obstacle_pushout_edge_material;693}694695Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));696material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);697material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);698///material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);699//material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);700material->set_albedo(debug_navigation_avoidance_static_obstacle_pushout_edge_color);701//material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 2);702material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);703704debug_navigation_avoidance_static_obstacle_pushout_edge_material = material;705return debug_navigation_avoidance_static_obstacle_pushout_edge_material;706}707708void NavigationServer3D::set_debug_navigation_edge_connection_color(const Color &p_color) {709debug_navigation_edge_connection_color = p_color;710if (debug_navigation_edge_connections_material.is_valid()) {711debug_navigation_edge_connections_material->set_albedo(debug_navigation_edge_connection_color);712}713}714715Color NavigationServer3D::get_debug_navigation_edge_connection_color() const {716return debug_navigation_edge_connection_color;717}718719void NavigationServer3D::set_debug_navigation_geometry_edge_color(const Color &p_color) {720debug_navigation_geometry_edge_color = p_color;721if (debug_navigation_geometry_edge_material.is_valid()) {722debug_navigation_geometry_edge_material->set_albedo(debug_navigation_geometry_edge_color);723}724}725726Color NavigationServer3D::get_debug_navigation_geometry_edge_color() const {727return debug_navigation_geometry_edge_color;728}729730void NavigationServer3D::set_debug_navigation_geometry_face_color(const Color &p_color) {731debug_navigation_geometry_face_color = p_color;732if (debug_navigation_geometry_face_material.is_valid()) {733debug_navigation_geometry_face_material->set_albedo(debug_navigation_geometry_face_color);734}735}736737Color NavigationServer3D::get_debug_navigation_geometry_face_color() const {738return debug_navigation_geometry_face_color;739}740741void NavigationServer3D::set_debug_navigation_geometry_edge_disabled_color(const Color &p_color) {742debug_navigation_geometry_edge_disabled_color = p_color;743if (debug_navigation_geometry_edge_disabled_material.is_valid()) {744debug_navigation_geometry_edge_disabled_material->set_albedo(debug_navigation_geometry_edge_disabled_color);745}746}747748Color NavigationServer3D::get_debug_navigation_geometry_edge_disabled_color() const {749return debug_navigation_geometry_edge_disabled_color;750}751752void NavigationServer3D::set_debug_navigation_geometry_face_disabled_color(const Color &p_color) {753debug_navigation_geometry_face_disabled_color = p_color;754if (debug_navigation_geometry_face_disabled_material.is_valid()) {755debug_navigation_geometry_face_disabled_material->set_albedo(debug_navigation_geometry_face_disabled_color);756}757}758759Color NavigationServer3D::get_debug_navigation_geometry_face_disabled_color() const {760return debug_navigation_geometry_face_disabled_color;761}762763void NavigationServer3D::set_debug_navigation_link_connection_color(const Color &p_color) {764debug_navigation_link_connection_color = p_color;765if (debug_navigation_link_connections_material.is_valid()) {766debug_navigation_link_connections_material->set_albedo(debug_navigation_link_connection_color);767}768}769770Color NavigationServer3D::get_debug_navigation_link_connection_color() const {771return debug_navigation_link_connection_color;772}773774void NavigationServer3D::set_debug_navigation_link_connection_disabled_color(const Color &p_color) {775debug_navigation_link_connection_disabled_color = p_color;776if (debug_navigation_link_connections_disabled_material.is_valid()) {777debug_navigation_link_connections_disabled_material->set_albedo(debug_navigation_link_connection_disabled_color);778}779}780781Color NavigationServer3D::get_debug_navigation_link_connection_disabled_color() const {782return debug_navigation_link_connection_disabled_color;783}784785void NavigationServer3D::set_debug_navigation_agent_path_point_size(real_t p_point_size) {786debug_navigation_agent_path_point_size = MAX(0.1, p_point_size);787if (debug_navigation_agent_path_point_material.is_valid()) {788debug_navigation_agent_path_point_material->set_point_size(debug_navigation_agent_path_point_size);789}790}791792real_t NavigationServer3D::get_debug_navigation_agent_path_point_size() const {793return debug_navigation_agent_path_point_size;794}795796void NavigationServer3D::set_debug_navigation_agent_path_color(const Color &p_color) {797debug_navigation_agent_path_color = p_color;798if (debug_navigation_agent_path_line_material.is_valid()) {799debug_navigation_agent_path_line_material->set_albedo(debug_navigation_agent_path_color);800}801if (debug_navigation_agent_path_point_material.is_valid()) {802debug_navigation_agent_path_point_material->set_albedo(debug_navigation_agent_path_color);803}804}805806Color NavigationServer3D::get_debug_navigation_agent_path_color() const {807return debug_navigation_agent_path_color;808}809810void NavigationServer3D::set_debug_navigation_enable_edge_connections(const bool p_value) {811debug_navigation_enable_edge_connections = p_value;812navigation_debug_dirty = true;813callable_mp(this, &NavigationServer3D::_emit_navigation_debug_changed_signal).call_deferred();814}815816bool NavigationServer3D::get_debug_navigation_enable_edge_connections() const {817return debug_navigation_enable_edge_connections;818}819820void NavigationServer3D::set_debug_navigation_enable_edge_connections_xray(const bool p_value) {821debug_navigation_enable_edge_connections_xray = p_value;822if (debug_navigation_edge_connections_material.is_valid()) {823debug_navigation_edge_connections_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_edge_connections_xray);824}825}826827bool NavigationServer3D::get_debug_navigation_enable_edge_connections_xray() const {828return debug_navigation_enable_edge_connections_xray;829}830831void NavigationServer3D::set_debug_navigation_enable_edge_lines(const bool p_value) {832debug_navigation_enable_edge_lines = p_value;833navigation_debug_dirty = true;834callable_mp(this, &NavigationServer3D::_emit_navigation_debug_changed_signal).call_deferred();835}836837bool NavigationServer3D::get_debug_navigation_enable_edge_lines() const {838return debug_navigation_enable_edge_lines;839}840841void NavigationServer3D::set_debug_navigation_enable_edge_lines_xray(const bool p_value) {842debug_navigation_enable_edge_lines_xray = p_value;843if (debug_navigation_geometry_edge_material.is_valid()) {844debug_navigation_geometry_edge_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_edge_lines_xray);845}846}847848bool NavigationServer3D::get_debug_navigation_enable_edge_lines_xray() const {849return debug_navigation_enable_edge_lines_xray;850}851852void NavigationServer3D::set_debug_navigation_enable_geometry_face_random_color(const bool p_value) {853debug_navigation_enable_geometry_face_random_color = p_value;854navigation_debug_dirty = true;855callable_mp(this, &NavigationServer3D::_emit_navigation_debug_changed_signal).call_deferred();856}857858bool NavigationServer3D::get_debug_navigation_enable_geometry_face_random_color() const {859return debug_navigation_enable_geometry_face_random_color;860}861862void NavigationServer3D::set_debug_navigation_enable_link_connections(const bool p_value) {863debug_navigation_enable_link_connections = p_value;864navigation_debug_dirty = true;865callable_mp(this, &NavigationServer3D::_emit_navigation_debug_changed_signal).call_deferred();866}867868bool NavigationServer3D::get_debug_navigation_enable_link_connections() const {869return debug_navigation_enable_link_connections;870}871872void NavigationServer3D::set_debug_navigation_enable_link_connections_xray(const bool p_value) {873debug_navigation_enable_link_connections_xray = p_value;874if (debug_navigation_link_connections_material.is_valid()) {875debug_navigation_link_connections_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_link_connections_xray);876}877}878879bool NavigationServer3D::get_debug_navigation_enable_link_connections_xray() const {880return debug_navigation_enable_link_connections_xray;881}882883void NavigationServer3D::set_debug_navigation_avoidance_enable_agents_radius(const bool p_value) {884debug_navigation_avoidance_enable_agents_radius = p_value;885avoidance_debug_dirty = true;886callable_mp(this, &NavigationServer3D::_emit_avoidance_debug_changed_signal).call_deferred();887}888889bool NavigationServer3D::get_debug_navigation_avoidance_enable_agents_radius() const {890return debug_navigation_avoidance_enable_agents_radius;891}892893void NavigationServer3D::set_debug_navigation_avoidance_enable_obstacles_radius(const bool p_value) {894debug_navigation_avoidance_enable_obstacles_radius = p_value;895avoidance_debug_dirty = true;896callable_mp(this, &NavigationServer3D::_emit_avoidance_debug_changed_signal).call_deferred();897}898899bool NavigationServer3D::get_debug_navigation_avoidance_enable_obstacles_radius() const {900return debug_navigation_avoidance_enable_obstacles_radius;901}902903void NavigationServer3D::set_debug_navigation_avoidance_enable_obstacles_static(const bool p_value) {904debug_navigation_avoidance_enable_obstacles_static = p_value;905avoidance_debug_dirty = true;906callable_mp(this, &NavigationServer3D::_emit_avoidance_debug_changed_signal).call_deferred();907}908909bool NavigationServer3D::get_debug_navigation_avoidance_enable_obstacles_static() const {910return debug_navigation_avoidance_enable_obstacles_static;911}912913void NavigationServer3D::set_debug_navigation_avoidance_agents_radius_color(const Color &p_color) {914debug_navigation_avoidance_agents_radius_color = p_color;915if (debug_navigation_avoidance_agents_radius_material.is_valid()) {916debug_navigation_avoidance_agents_radius_material->set_albedo(debug_navigation_avoidance_agents_radius_color);917}918}919920Color NavigationServer3D::get_debug_navigation_avoidance_agents_radius_color() const {921return debug_navigation_avoidance_agents_radius_color;922}923924void NavigationServer3D::set_debug_navigation_avoidance_obstacles_radius_color(const Color &p_color) {925debug_navigation_avoidance_obstacles_radius_color = p_color;926if (debug_navigation_avoidance_obstacles_radius_material.is_valid()) {927debug_navigation_avoidance_obstacles_radius_material->set_albedo(debug_navigation_avoidance_obstacles_radius_color);928}929}930931Color NavigationServer3D::get_debug_navigation_avoidance_obstacles_radius_color() const {932return debug_navigation_avoidance_obstacles_radius_color;933}934935void NavigationServer3D::set_debug_navigation_avoidance_static_obstacle_pushin_face_color(const Color &p_color) {936debug_navigation_avoidance_static_obstacle_pushin_face_color = p_color;937if (debug_navigation_avoidance_static_obstacle_pushin_face_material.is_valid()) {938debug_navigation_avoidance_static_obstacle_pushin_face_material->set_albedo(debug_navigation_avoidance_static_obstacle_pushin_face_color);939}940}941942Color NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushin_face_color() const {943return debug_navigation_avoidance_static_obstacle_pushin_face_color;944}945946void NavigationServer3D::set_debug_navigation_avoidance_static_obstacle_pushout_face_color(const Color &p_color) {947debug_navigation_avoidance_static_obstacle_pushout_face_color = p_color;948if (debug_navigation_avoidance_static_obstacle_pushout_face_material.is_valid()) {949debug_navigation_avoidance_static_obstacle_pushout_face_material->set_albedo(debug_navigation_avoidance_static_obstacle_pushout_face_color);950}951}952953Color NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushout_face_color() const {954return debug_navigation_avoidance_static_obstacle_pushout_face_color;955}956957void NavigationServer3D::set_debug_navigation_avoidance_static_obstacle_pushin_edge_color(const Color &p_color) {958debug_navigation_avoidance_static_obstacle_pushin_edge_color = p_color;959if (debug_navigation_avoidance_static_obstacle_pushin_edge_material.is_valid()) {960debug_navigation_avoidance_static_obstacle_pushin_edge_material->set_albedo(debug_navigation_avoidance_static_obstacle_pushin_edge_color);961}962}963964Color NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushin_edge_color() const {965return debug_navigation_avoidance_static_obstacle_pushin_edge_color;966}967968void NavigationServer3D::set_debug_navigation_avoidance_static_obstacle_pushout_edge_color(const Color &p_color) {969debug_navigation_avoidance_static_obstacle_pushout_edge_color = p_color;970if (debug_navigation_avoidance_static_obstacle_pushout_edge_material.is_valid()) {971debug_navigation_avoidance_static_obstacle_pushout_edge_material->set_albedo(debug_navigation_avoidance_static_obstacle_pushout_edge_color);972}973}974975Color NavigationServer3D::get_debug_navigation_avoidance_static_obstacle_pushout_edge_color() const {976return debug_navigation_avoidance_static_obstacle_pushout_edge_color;977}978979void NavigationServer3D::set_debug_navigation_enable_agent_paths(const bool p_value) {980if (debug_navigation_enable_agent_paths != p_value) {981debug_dirty = true;982}983984debug_navigation_enable_agent_paths = p_value;985986if (debug_dirty) {987callable_mp(this, &NavigationServer3D::_emit_navigation_debug_changed_signal).call_deferred();988}989}990991bool NavigationServer3D::get_debug_navigation_enable_agent_paths() const {992return debug_navigation_enable_agent_paths;993}994995void NavigationServer3D::set_debug_navigation_enable_agent_paths_xray(const bool p_value) {996debug_navigation_enable_agent_paths_xray = p_value;997if (debug_navigation_agent_path_line_material.is_valid()) {998debug_navigation_agent_path_line_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_agent_paths_xray);999}1000if (debug_navigation_agent_path_point_material.is_valid()) {1001debug_navigation_agent_path_point_material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, debug_navigation_enable_agent_paths_xray);1002}1003}10041005bool NavigationServer3D::get_debug_navigation_enable_agent_paths_xray() const {1006return debug_navigation_enable_agent_paths_xray;1007}10081009void NavigationServer3D::set_debug_navigation_enabled(bool p_enabled) {1010debug_navigation_enabled = p_enabled;1011navigation_debug_dirty = true;1012callable_mp(this, &NavigationServer3D::_emit_navigation_debug_changed_signal).call_deferred();1013}10141015bool NavigationServer3D::get_debug_navigation_enabled() const {1016return debug_navigation_enabled;1017}10181019void NavigationServer3D::set_debug_avoidance_enabled(bool p_enabled) {1020debug_avoidance_enabled = p_enabled;1021avoidance_debug_dirty = true;1022callable_mp(this, &NavigationServer3D::_emit_avoidance_debug_changed_signal).call_deferred();1023}10241025bool NavigationServer3D::get_debug_avoidance_enabled() const {1026return debug_avoidance_enabled;1027}10281029#endif // DEBUG_ENABLED10301031///////////////////////////////////////////////////////10321033static NavigationServer3D *navigation_server_3d = nullptr;10341035NavigationServer3DCallback NavigationServer3DManager::create_callback = nullptr;10361037void NavigationServer3DManager::set_default_server(NavigationServer3DCallback p_callback) {1038create_callback = p_callback;1039}10401041NavigationServer3D *NavigationServer3DManager::new_default_server() {1042if (create_callback == nullptr) {1043return nullptr;1044}10451046return create_callback();1047}10481049void NavigationServer3DManager::initialize_server() {1050ERR_FAIL_COND(navigation_server_3d != nullptr);10511052// Init 3D Navigation Server1053navigation_server_3d = NavigationServer3DManager::new_default_server();10541055// Fall back to dummy if no default server has been registered.1056if (!navigation_server_3d) {1057WARN_VERBOSE("Failed to initialize NavigationServer3D. Fall back to dummy server.");1058navigation_server_3d = memnew(NavigationServer3DDummy);1059}10601061// Should be impossible, but make sure it's not null.1062ERR_FAIL_NULL_MSG(navigation_server_3d, "Failed to initialize NavigationServer3D.");1063navigation_server_3d->init();1064}10651066void NavigationServer3DManager::finalize_server() {1067ERR_FAIL_NULL(navigation_server_3d);1068navigation_server_3d->finish();1069memdelete(navigation_server_3d);1070navigation_server_3d = nullptr;1071}107210731074