Allow to compile templates without navigation features

This commit is contained in:
Michael Alexsander
2025-03-30 13:20:04 -03:00
parent d52b84e472
commit 556933306a
79 changed files with 665 additions and 220 deletions

View File

@ -45,11 +45,14 @@
#include "scene/resources/3d/sphere_shape_3d.h"
#include "scene/resources/physics_material.h"
#include "scene/resources/surface_tool.h"
#include "servers/navigation_server_3d.h"
#include "servers/rendering_server.h"
#ifndef NAVIGATION_3D_DISABLED
#include "servers/navigation_server_3d.h"
Callable GridMap::_navmesh_source_geometry_parsing_callback;
RID GridMap::_navmesh_source_geometry_parser;
#endif // NAVIGATION_3D_DISABLED
bool GridMap::_set(const StringName &p_name, const Variant &p_value) {
String name = p_name;
@ -247,6 +250,7 @@ bool GridMap::is_baking_navigation() {
return bake_navigation;
}
#ifndef NAVIGATION_3D_DISABLED
void GridMap::set_navigation_map(RID p_navigation_map) {
map_override = p_navigation_map;
for (const KeyValue<OctantKey, Octant *> &E : octant_map) {
@ -267,6 +271,7 @@ RID GridMap::get_navigation_map() const {
}
return RID();
}
#endif // NAVIGATION_3D_DISABLED
void GridMap::set_mesh_library(const Ref<MeshLibrary> &p_mesh_library) {
if (mesh_library.is_valid()) {
@ -541,6 +546,7 @@ void GridMap::_octant_transform(const OctantKey &p_key) {
}
#endif // PHYSICS_3D_DISABLED
#ifndef NAVIGATION_3D_DISABLED
// update transform for NavigationServer regions and navigation debugmesh instances
for (const KeyValue<IndexKey, Octant::NavigationCell> &E : g.navigation_cell_ids) {
if (bake_navigation) {
@ -552,6 +558,7 @@ void GridMap::_octant_transform(const OctantKey &p_key) {
}
}
}
#endif // NAVIGATION_3D_DISABLED
for (int i = 0; i < g.multimesh_instances.size(); i++) {
RS::get_singleton()->instance_set_transform(g.multimesh_instances[i].instance, get_global_transform());
@ -575,6 +582,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
}
#endif // PHYSICS_3D_DISABLED
#ifndef NAVIGATION_3D_DISABLED
//erase navigation
for (KeyValue<IndexKey, Octant::NavigationCell> &E : g.navigation_cell_ids) {
if (E.value.region.is_valid()) {
@ -587,6 +595,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
}
}
g.navigation_cell_ids.clear();
#endif // NAVIGATION_3D_DISABLED
//erase multimeshes
@ -656,6 +665,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
}
#endif // PHYSICS_3D_DISABLED
#ifndef NAVIGATION_3D_DISABLED
// add the item's navigation_mesh at given xform to GridMap's Navigation ancestor
Ref<NavigationMesh> navigation_mesh = mesh_library->get_item_navigation_mesh(c.item);
if (navigation_mesh.is_valid()) {
@ -696,13 +706,14 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
}
g.navigation_cell_ids[E] = nm;
}
#endif // NAVIGATION_3D_DISABLED
}
#ifdef DEBUG_ENABLED
#if defined(DEBUG_ENABLED) && !defined(NAVIGATION_3D_DISABLED)
if (bake_navigation) {
_update_octant_navigation_debug_edge_connections_mesh(p_key);
}
#endif // DEBUG_ENABLED
#endif // defined(DEBUG_ENABLED) && !defined(NAVIGATION_3D_DISABLED)
//update multimeshes, only if not baked
if (baked_meshes.size() == 0) {
@ -806,6 +817,7 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) {
RS::get_singleton()->instance_set_transform(g.multimesh_instances[i].instance, get_global_transform());
}
#ifndef NAVIGATION_3D_DISABLED
if (bake_navigation && mesh_library.is_valid()) {
for (KeyValue<IndexKey, Octant::NavigationCell> &F : g.navigation_cell_ids) {
if (cell_map.has(F.key) && F.value.region.is_valid() == false) {
@ -840,6 +852,7 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) {
}
#endif // DEBUG_ENABLED
}
#endif // NAVIGATION_3D_DISABLED
}
void GridMap::_octant_exit_world(const OctantKey &p_key) {
@ -847,7 +860,9 @@ void GridMap::_octant_exit_world(const OctantKey &p_key) {
#ifndef PHYSICS_3D_DISABLED
ERR_FAIL_NULL(PhysicsServer3D::get_singleton());
#endif // PHYSICS_3D_DISABLED
#ifndef NAVIGATION_3D_DISABLED
ERR_FAIL_NULL(NavigationServer3D::get_singleton());
#endif // NAVIGATION_3D_DISABLED
ERR_FAIL_COND(!octant_map.has(p_key));
Octant &g = *octant_map[p_key];
@ -865,6 +880,7 @@ void GridMap::_octant_exit_world(const OctantKey &p_key) {
RS::get_singleton()->instance_set_scenario(g.multimesh_instances[i].instance, RID());
}
#ifndef NAVIGATION_3D_DISABLED
for (KeyValue<IndexKey, Octant::NavigationCell> &F : g.navigation_cell_ids) {
if (F.value.region.is_valid()) {
NavigationServer3D::get_singleton()->free(F.value.region);
@ -875,6 +891,7 @@ void GridMap::_octant_exit_world(const OctantKey &p_key) {
F.value.navigation_mesh_debug_instance = RID();
}
}
#endif // NAVIGATION_3D_DISABLED
#ifdef DEBUG_ENABLED
if (bake_navigation) {
@ -894,7 +911,9 @@ void GridMap::_octant_clean_up(const OctantKey &p_key) {
#ifndef PHYSICS_3D_DISABLED
ERR_FAIL_NULL(PhysicsServer3D::get_singleton());
#endif // PHYSICS_3D_DISABLED
#ifndef NAVIGATION_3D_DISABLED
ERR_FAIL_NULL(NavigationServer3D::get_singleton());
#endif // NAVIGATION_3D_DISABLED
ERR_FAIL_COND(!octant_map.has(p_key));
Octant &g = *octant_map[p_key];
@ -910,6 +929,7 @@ void GridMap::_octant_clean_up(const OctantKey &p_key) {
PhysicsServer3D::get_singleton()->free(g.static_body);
#endif // PHYSICS_3D_DISABLED
#ifndef NAVIGATION_3D_DISABLED
// Erase navigation
for (const KeyValue<IndexKey, Octant::NavigationCell> &E : g.navigation_cell_ids) {
if (E.value.region.is_valid()) {
@ -920,6 +940,7 @@ void GridMap::_octant_clean_up(const OctantKey &p_key) {
}
}
g.navigation_cell_ids.clear();
#endif // NAVIGATION_3D_DISABLED
#ifdef DEBUG_ENABLED
if (bake_navigation) {
@ -958,11 +979,11 @@ void GridMap::_notification(int p_what) {
} break;
case NOTIFICATION_ENTER_TREE: {
#ifdef DEBUG_ENABLED
#if defined(DEBUG_ENABLED) && !defined(NAVIGATION_3D_DISABLED)
if (bake_navigation && NavigationServer3D::get_singleton()->get_debug_navigation_enabled()) {
_update_navigation_debug_edge_connections();
}
#endif // DEBUG_ENABLED
#endif // defined(DEBUG_ENABLED) && !defined(NAVIGATION_3D_DISABLED)
_update_visibility();
} break;
@ -1109,8 +1130,10 @@ void GridMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_bake_navigation", "bake_navigation"), &GridMap::set_bake_navigation);
ClassDB::bind_method(D_METHOD("is_baking_navigation"), &GridMap::is_baking_navigation);
#ifndef NAVIGATION_3D_DISABLED
ClassDB::bind_method(D_METHOD("set_navigation_map", "navigation_map"), &GridMap::set_navigation_map);
ClassDB::bind_method(D_METHOD("get_navigation_map"), &GridMap::get_navigation_map);
#endif // NAVIGATION_3D_DISABLED
ClassDB::bind_method(D_METHOD("set_mesh_library", "mesh_library"), &GridMap::set_mesh_library);
ClassDB::bind_method(D_METHOD("get_mesh_library"), &GridMap::get_mesh_library);
@ -1373,12 +1396,13 @@ RID GridMap::get_bake_mesh_instance(int p_idx) {
GridMap::GridMap() {
set_notify_transform(true);
#ifdef DEBUG_ENABLED
#if defined(DEBUG_ENABLED) && !defined(NAVIGATION_3D_DISABLED)
NavigationServer3D::get_singleton()->connect("map_changed", callable_mp(this, &GridMap::_navigation_map_changed));
NavigationServer3D::get_singleton()->connect("navigation_debug_changed", callable_mp(this, &GridMap::_update_navigation_debug_edge_connections));
#endif // DEBUG_ENABLED
#endif // defined(DEBUG_ENABLED) && !defined(NAVIGATION_3D_DISABLED)
}
#ifndef NAVIGATION_3D_DISABLED
void GridMap::navmesh_parse_init() {
ERR_FAIL_NULL(NavigationServer3D::get_singleton());
if (!_navmesh_source_geometry_parser.is_valid()) {
@ -1518,8 +1542,9 @@ void GridMap::navmesh_parse_source_geometry(const Ref<NavigationMesh> &p_navigat
}
#endif // PHYSICS_3D_DISABLED
}
#endif // NAVIGATION_3D_DISABLED
#ifdef DEBUG_ENABLED
#if defined(DEBUG_ENABLED) && !defined(NAVIGATION_3D_DISABLED)
void GridMap::_update_navigation_debug_edge_connections() {
if (bake_navigation) {
for (const KeyValue<OctantKey, Octant *> &E : octant_map) {
@ -1533,17 +1558,17 @@ void GridMap::_navigation_map_changed(RID p_map) {
_update_navigation_debug_edge_connections();
}
}
#endif // DEBUG_ENABLED
#endif // defined(DEBUG_ENABLED) && !defined(NAVIGATION_3D_DISABLED)
GridMap::~GridMap() {
clear();
#ifdef DEBUG_ENABLED
#if defined(DEBUG_ENABLED) && !defined(NAVIGATION_3D_DISABLED)
NavigationServer3D::get_singleton()->disconnect("map_changed", callable_mp(this, &GridMap::_navigation_map_changed));
NavigationServer3D::get_singleton()->disconnect("navigation_debug_changed", callable_mp(this, &GridMap::_update_navigation_debug_edge_connections));
#endif // DEBUG_ENABLED
#endif // defined(DEBUG_ENABLED) && !defined(NAVIGATION_3D_DISABLED)
}
#ifdef DEBUG_ENABLED
#if defined(DEBUG_ENABLED) && !defined(NAVIGATION_3D_DISABLED)
void GridMap::_update_octant_navigation_debug_edge_connections_mesh(const OctantKey &p_key) {
ERR_FAIL_COND(!octant_map.has(p_key));
Octant &g = *octant_map[p_key];
@ -1641,4 +1666,4 @@ void GridMap::_update_octant_navigation_debug_edge_connections_mesh(const Octant
RS::get_singleton()->instance_set_visible(g.navigation_debug_edge_connections_instance, false);
}
}
#endif // DEBUG_ENABLED
#endif // defined(DEBUG_ENABLED) && !defined(NAVIGATION_3D_DISABLED)