diff --git a/doc/classes/NavigationRegion3D.xml b/doc/classes/NavigationRegion3D.xml index 10662db8691c..dd26852bb711 100644 --- a/doc/classes/NavigationRegion3D.xml +++ b/doc/classes/NavigationRegion3D.xml @@ -20,6 +20,7 @@ Bakes the [NavigationMesh]. If [param on_thread] is set to [code]true[/code] (default), the baking is done on a separate thread. Baking on separate thread is useful because navigation baking is not a cheap operation. When it is completed, it automatically sets the new [NavigationMesh]. Please note that baking on separate thread may be very slow if geometry is parsed from meshes as async access to each mesh involves heavy synchronization. Also, please note that baking on a separate thread is automatically disabled on operating systems that cannot use threads (such as Web with threads disabled). + [b]Note:[/b] Only functional in Godot builds with NavigationMeshGenerator module enabled. diff --git a/doc/classes/NavigationServer3D.xml b/doc/classes/NavigationServer3D.xml index c156dfac163b..b38bde61a18c 100644 --- a/doc/classes/NavigationServer3D.xml +++ b/doc/classes/NavigationServer3D.xml @@ -433,14 +433,6 @@ Queries a path in a given navigation map. Start and target position and other parameters are defined through [NavigationPathQueryParameters3D]. Updates the provided [NavigationPathQueryResult3D] result object with the path among other results requested by the query. - - - - - - Bakes the [param navigation_mesh] with bake source geometry collected starting from the [param root_node]. - - diff --git a/modules/navigation/SCsub b/modules/navigation/SCsub index 0b0822db2da5..0b7c8779bae8 100644 --- a/modules/navigation/SCsub +++ b/modules/navigation/SCsub @@ -9,30 +9,6 @@ env_navigation = env_modules.Clone() thirdparty_obj = [] -# Recast Thirdparty source files -if env["builtin_recast"]: - thirdparty_dir = "#thirdparty/recastnavigation/Recast/" - thirdparty_sources = [ - "Source/Recast.cpp", - "Source/RecastAlloc.cpp", - "Source/RecastArea.cpp", - "Source/RecastAssert.cpp", - "Source/RecastContour.cpp", - "Source/RecastFilter.cpp", - "Source/RecastLayers.cpp", - "Source/RecastMesh.cpp", - "Source/RecastMeshDetail.cpp", - "Source/RecastRasterization.cpp", - "Source/RecastRegion.cpp", - ] - thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] - - env_navigation.Prepend(CPPPATH=[thirdparty_dir + "Include"]) - - env_thirdparty = env_navigation.Clone() - env_thirdparty.disable_warnings() - env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources) - # RVO Thirdparty source files if env["builtin_rvo2"]: thirdparty_dir = "#thirdparty/rvo2/" @@ -57,8 +33,6 @@ env.modules_sources += thirdparty_obj module_obj = [] env_navigation.add_source_files(module_obj, "*.cpp") -if env.editor_build: - env_navigation.add_source_files(module_obj, "editor/*.cpp") env.modules_sources += module_obj # Needed to force rebuilding the module files when the thirdparty library is updated. diff --git a/modules/navigation/godot_navigation_server.cpp b/modules/navigation/godot_navigation_server.cpp index 58a09824256e..469b6b0d015c 100644 --- a/modules/navigation/godot_navigation_server.cpp +++ b/modules/navigation/godot_navigation_server.cpp @@ -32,10 +32,6 @@ #include "core/os/mutex.h" -#ifndef _3D_DISABLED -#include "navigation_mesh_generator.h" -#endif - using namespace NavigationUtilities; /// Creates a struct for each function and a function that once called creates @@ -430,16 +426,6 @@ COMMAND_2(region_set_navigation_mesh, RID, p_region, Ref, p_navi region->set_mesh(p_navigation_mesh); } -void GodotNavigationServer::region_bake_navigation_mesh(Ref p_navigation_mesh, Node *p_root_node) const { - ERR_FAIL_COND(p_navigation_mesh.is_null()); - ERR_FAIL_COND(p_root_node == nullptr); - -#ifndef _3D_DISABLED - NavigationMeshGenerator::get_singleton()->clear(p_navigation_mesh); - NavigationMeshGenerator::get_singleton()->bake(p_navigation_mesh, p_root_node); -#endif -} - int GodotNavigationServer::region_get_connections_count(RID p_region) const { NavRegion *region = region_owner.get_or_null(p_region); ERR_FAIL_COND_V(!region, 0); diff --git a/modules/navigation/godot_navigation_server.h b/modules/navigation/godot_navigation_server.h index 6f39420c6777..46359a05f0ab 100644 --- a/modules/navigation/godot_navigation_server.h +++ b/modules/navigation/godot_navigation_server.h @@ -136,7 +136,6 @@ class GodotNavigationServer : public NavigationServer3D { virtual uint32_t region_get_navigation_layers(RID p_region) const override; COMMAND_2(region_set_transform, RID, p_region, Transform3D, p_transform); COMMAND_2(region_set_navigation_mesh, RID, p_region, Ref, p_navigation_mesh); - virtual void region_bake_navigation_mesh(Ref p_navigation_mesh, Node *p_root_node) const override; virtual int region_get_connections_count(RID p_region) const override; virtual Vector3 region_get_connection_pathway_start(RID p_region, int p_connection_id) const override; virtual Vector3 region_get_connection_pathway_end(RID p_region, int p_connection_id) const override; diff --git a/modules/navigation/register_types.cpp b/modules/navigation/register_types.cpp index 62ae2c7f02db..a7659f0daa54 100644 --- a/modules/navigation/register_types.cpp +++ b/modules/navigation/register_types.cpp @@ -30,22 +30,8 @@ #include "register_types.h" -#include "core/config/engine.h" -#include "servers/navigation_server_3d.h" - #include "godot_navigation_server.h" - -#ifndef _3D_DISABLED -#include "navigation_mesh_generator.h" -#endif - -#ifdef TOOLS_ENABLED -#include "editor/navigation_mesh_editor_plugin.h" -#endif - -#ifndef _3D_DISABLED -NavigationMeshGenerator *_nav_mesh_generator = nullptr; -#endif +#include "servers/navigation_server_3d.h" NavigationServer3D *new_server() { return memnew(GodotNavigationServer); @@ -54,29 +40,8 @@ NavigationServer3D *new_server() { void initialize_navigation_module(ModuleInitializationLevel p_level) { if (p_level == MODULE_INITIALIZATION_LEVEL_SERVERS) { NavigationServer3DManager::set_default_server(new_server); - -#ifndef _3D_DISABLED - _nav_mesh_generator = memnew(NavigationMeshGenerator); - GDREGISTER_CLASS(NavigationMeshGenerator); - Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationMeshGenerator", NavigationMeshGenerator::get_singleton())); -#endif - } - -#ifdef TOOLS_ENABLED - if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) { - EditorPlugins::add_by_type(); } -#endif } void uninitialize_navigation_module(ModuleInitializationLevel p_level) { - if (p_level != MODULE_INITIALIZATION_LEVEL_SERVERS) { - return; - } - -#ifndef _3D_DISABLED - if (_nav_mesh_generator) { - memdelete(_nav_mesh_generator); - } -#endif } diff --git a/modules/navigation_mesh_generator/SCsub b/modules/navigation_mesh_generator/SCsub new file mode 100644 index 000000000000..92ecabd9f6a4 --- /dev/null +++ b/modules/navigation_mesh_generator/SCsub @@ -0,0 +1,48 @@ +#!/usr/bin/env python + +Import("env") +Import("env_modules") + +env_navigation_mesh_generator = env_modules.Clone() + +# Thirdparty source files + +thirdparty_obj = [] + +# Recast Thirdparty source files +if env["builtin_recast"]: + thirdparty_dir = "#thirdparty/recastnavigation/Recast/" + thirdparty_sources = [ + "Source/Recast.cpp", + "Source/RecastAlloc.cpp", + "Source/RecastArea.cpp", + "Source/RecastAssert.cpp", + "Source/RecastContour.cpp", + "Source/RecastFilter.cpp", + "Source/RecastLayers.cpp", + "Source/RecastMesh.cpp", + "Source/RecastMeshDetail.cpp", + "Source/RecastRasterization.cpp", + "Source/RecastRegion.cpp", + ] + thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] + + env_navigation_mesh_generator.Prepend(CPPPATH=[thirdparty_dir + "Include"]) + + env_thirdparty = env_navigation_mesh_generator.Clone() + env_thirdparty.disable_warnings() + env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources) + +env.modules_sources += thirdparty_obj + +# Godot source files + +module_obj = [] + +env_navigation_mesh_generator.add_source_files(module_obj, "*.cpp") +if env.editor_build: + env_navigation_mesh_generator.add_source_files(module_obj, "editor/*.cpp") +env.modules_sources += module_obj + +# Needed to force rebuilding the module files when the thirdparty library is updated. +env.Depends(module_obj, thirdparty_obj) diff --git a/modules/navigation_mesh_generator/config.py b/modules/navigation_mesh_generator/config.py new file mode 100644 index 000000000000..4a7cee93a2bf --- /dev/null +++ b/modules/navigation_mesh_generator/config.py @@ -0,0 +1,16 @@ +def can_build(env, platform): + return True + + +def configure(env): + pass + + +def get_doc_classes(): + return [ + "NavigationMeshGenerator", + ] + + +def get_doc_path(): + return "doc_classes" diff --git a/doc/classes/NavigationMeshGenerator.xml b/modules/navigation_mesh_generator/doc_classes/NavigationMeshGenerator.xml similarity index 98% rename from doc/classes/NavigationMeshGenerator.xml rename to modules/navigation_mesh_generator/doc_classes/NavigationMeshGenerator.xml index 15d149a22936..ca8cd14178a4 100644 --- a/doc/classes/NavigationMeshGenerator.xml +++ b/modules/navigation_mesh_generator/doc_classes/NavigationMeshGenerator.xml @@ -1,5 +1,5 @@ - + Helper class for creating and clearing navigation meshes. diff --git a/modules/navigation_mesh_generator/editor/SCsub b/modules/navigation_mesh_generator/editor/SCsub new file mode 100644 index 000000000000..359d04e5df2a --- /dev/null +++ b/modules/navigation_mesh_generator/editor/SCsub @@ -0,0 +1,5 @@ +#!/usr/bin/env python + +Import("env") + +env.add_source_files(env.editor_sources, "*.cpp") diff --git a/modules/navigation/editor/navigation_mesh_editor_plugin.cpp b/modules/navigation_mesh_generator/editor/navigation_mesh_editor_plugin.cpp similarity index 99% rename from modules/navigation/editor/navigation_mesh_editor_plugin.cpp rename to modules/navigation_mesh_generator/editor/navigation_mesh_editor_plugin.cpp index 32abc520173f..178742eedc9e 100644 --- a/modules/navigation/editor/navigation_mesh_editor_plugin.cpp +++ b/modules/navigation_mesh_generator/editor/navigation_mesh_editor_plugin.cpp @@ -37,6 +37,7 @@ #include "core/io/resource_saver.h" #include "editor/editor_node.h" #include "scene/3d/mesh_instance_3d.h" +#include "scene/3d/navigation_region_3d.h" #include "scene/gui/box_container.h" void NavigationMeshEditor::_node_removed(Node *p_node) { diff --git a/modules/navigation/editor/navigation_mesh_editor_plugin.h b/modules/navigation_mesh_generator/editor/navigation_mesh_editor_plugin.h similarity index 100% rename from modules/navigation/editor/navigation_mesh_editor_plugin.h rename to modules/navigation_mesh_generator/editor/navigation_mesh_editor_plugin.h diff --git a/modules/navigation/navigation_mesh_generator.cpp b/modules/navigation_mesh_generator/navigation_mesh_generator.cpp similarity index 99% rename from modules/navigation/navigation_mesh_generator.cpp rename to modules/navigation_mesh_generator/navigation_mesh_generator.cpp index 62db6ff4e9f7..512db85a492f 100644 --- a/modules/navigation/navigation_mesh_generator.cpp +++ b/modules/navigation_mesh_generator/navigation_mesh_generator.cpp @@ -28,12 +28,12 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef _3D_DISABLED - #include "navigation_mesh_generator.h" #include "core/math/convex_hull.h" #include "core/os/thread.h" + +#ifndef _3D_DISABLED #include "scene/3d/mesh_instance_3d.h" #include "scene/3d/multimesh_instance_3d.h" #include "scene/3d/physics_body_3d.h" @@ -60,9 +60,21 @@ #ifdef MODULE_GRIDMAP_ENABLED #include "modules/gridmap/grid_map.h" #endif +#endif // _3D_DISABLED NavigationMeshGenerator *NavigationMeshGenerator::singleton = nullptr; +NavigationMeshGenerator *NavigationMeshGenerator::get_singleton() { + return singleton; +} + +NavigationMeshGenerator::NavigationMeshGenerator() { + singleton = this; +} + +NavigationMeshGenerator::~NavigationMeshGenerator() { +} + void NavigationMeshGenerator::_add_vertex(const Vector3 &p_vec3, Vector &p_vertices) { p_vertices.push_back(p_vec3.x); p_vertices.push_back(p_vec3.y); @@ -162,6 +174,7 @@ void NavigationMeshGenerator::_add_faces(const PackedVector3Array &p_faces, cons } void NavigationMeshGenerator::_parse_geometry(const Transform3D &p_navmesh_transform, Node *p_node, Vector &p_vertices, Vector &p_indices, NavigationMesh::ParsedGeometryType p_generate_from, uint32_t p_collision_mask, bool p_recurse_children) { +#ifndef _3D_DISABLED if (Object::cast_to(p_node) && p_generate_from != NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS) { MeshInstance3D *mesh_instance = Object::cast_to(p_node); Ref mesh = mesh_instance->get_mesh(); @@ -468,8 +481,10 @@ void NavigationMeshGenerator::_parse_geometry(const Transform3D &p_navmesh_trans _parse_geometry(p_navmesh_transform, p_node->get_child(i), p_vertices, p_indices, p_generate_from, p_collision_mask, p_recurse_children); } } +#endif // _3D_DISABLED } +#ifndef _3D_DISABLED void NavigationMeshGenerator::_convert_detail_mesh_to_native_navigation_mesh(const rcPolyMeshDetail *p_detail_mesh, Ref p_navigation_mesh) { Vector nav_vertices; @@ -496,7 +511,9 @@ void NavigationMeshGenerator::_convert_detail_mesh_to_native_navigation_mesh(con } } } +#endif // _3D_DISABLED +#ifndef _3D_DISABLED void NavigationMeshGenerator::_build_recast_navigation_mesh( Ref p_navigation_mesh, #ifdef TOOLS_ENABLED @@ -717,20 +734,11 @@ void NavigationMeshGenerator::_build_recast_navigation_mesh( rcFreePolyMeshDetail(detail_mesh); detail_mesh = nullptr; } - -NavigationMeshGenerator *NavigationMeshGenerator::get_singleton() { - return singleton; -} - -NavigationMeshGenerator::NavigationMeshGenerator() { - singleton = this; -} - -NavigationMeshGenerator::~NavigationMeshGenerator() { -} +#endif // _3D_DISABLED void NavigationMeshGenerator::bake(Ref p_navigation_mesh, Node *p_root_node) { ERR_FAIL_COND_MSG(!p_navigation_mesh.is_valid(), "Invalid navigation mesh."); +#ifndef _3D_DISABLED #ifdef TOOLS_ENABLED EditorProgress *ep(nullptr); @@ -813,7 +821,8 @@ void NavigationMeshGenerator::bake(Ref p_navigation_mesh, Node * if (ep) { memdelete(ep); } -#endif +#endif // TOOLS_ENABLED +#endif // _3D_DISABLED } void NavigationMeshGenerator::clear(Ref p_navigation_mesh) { @@ -827,5 +836,3 @@ void NavigationMeshGenerator::_bind_methods() { ClassDB::bind_method(D_METHOD("bake", "navigation_mesh", "root_node"), &NavigationMeshGenerator::bake); ClassDB::bind_method(D_METHOD("clear", "navigation_mesh"), &NavigationMeshGenerator::clear); } - -#endif diff --git a/modules/navigation/navigation_mesh_generator.h b/modules/navigation_mesh_generator/navigation_mesh_generator.h similarity index 96% rename from modules/navigation/navigation_mesh_generator.h rename to modules/navigation_mesh_generator/navigation_mesh_generator.h index f6bf39d7142b..aa51031cd43e 100644 --- a/modules/navigation/navigation_mesh_generator.h +++ b/modules/navigation_mesh_generator/navigation_mesh_generator.h @@ -31,11 +31,12 @@ #ifndef NAVIGATION_MESH_GENERATOR_H #define NAVIGATION_MESH_GENERATOR_H +#include "scene/resources/navigation_mesh.h" #ifndef _3D_DISABLED - -#include "scene/3d/navigation_region_3d.h" - #include +#else +#include "scene/main/node.h" +#endif // _3D_DISABLED #ifdef TOOLS_ENABLED struct EditorProgress; @@ -55,6 +56,7 @@ class NavigationMeshGenerator : public Object { static void _add_faces(const PackedVector3Array &p_faces, const Transform3D &p_xform, Vector &p_vertices, Vector &p_indices); static void _parse_geometry(const Transform3D &p_navmesh_transform, Node *p_node, Vector &p_vertices, Vector &p_indices, NavigationMesh::ParsedGeometryType p_generate_from, uint32_t p_collision_mask, bool p_recurse_children); +#ifndef _3D_DISABLED static void _convert_detail_mesh_to_native_navigation_mesh(const rcPolyMeshDetail *p_detail_mesh, Ref p_navigation_mesh); static void _build_recast_navigation_mesh( Ref p_navigation_mesh, @@ -68,6 +70,7 @@ class NavigationMeshGenerator : public Object { rcPolyMeshDetail *detail_mesh, Vector &vertices, Vector &indices); +#endif // _3D_DISABLED public: static NavigationMeshGenerator *get_singleton(); @@ -79,6 +82,4 @@ class NavigationMeshGenerator : public Object { void clear(Ref p_navigation_mesh); }; -#endif - #endif // NAVIGATION_MESH_GENERATOR_H diff --git a/modules/navigation_mesh_generator/register_types.cpp b/modules/navigation_mesh_generator/register_types.cpp new file mode 100644 index 000000000000..b9ca1a4a137a --- /dev/null +++ b/modules/navigation_mesh_generator/register_types.cpp @@ -0,0 +1,62 @@ +/*************************************************************************/ +/* register_types.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "register_types.h" + +#include "core/config/engine.h" +#include "navigation_mesh_generator.h" + +#ifdef TOOLS_ENABLED +#include "editor/navigation_mesh_editor_plugin.h" +#endif // TOOLS_ENABLED + +NavigationMeshGenerator *_nav_mesh_generator = nullptr; + +void initialize_navigation_mesh_generator_module(ModuleInitializationLevel p_level) { + if (p_level == MODULE_INITIALIZATION_LEVEL_SERVERS) { + _nav_mesh_generator = memnew(NavigationMeshGenerator); + GDREGISTER_CLASS(NavigationMeshGenerator); + Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationMeshGenerator", NavigationMeshGenerator::get_singleton(), "NavigationMeshGenerator")); + } + +#ifdef TOOLS_ENABLED + if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) { + EditorPlugins::add_by_type(); + } +#endif // TOOLS_ENABLED +} + +void uninitialize_navigation_mesh_generator_module(ModuleInitializationLevel p_level) { + if (p_level == MODULE_INITIALIZATION_LEVEL_SERVERS) { + if (_nav_mesh_generator) { + memdelete(_nav_mesh_generator); + } + } +} diff --git a/modules/navigation_mesh_generator/register_types.h b/modules/navigation_mesh_generator/register_types.h new file mode 100644 index 000000000000..c5708732dc26 --- /dev/null +++ b/modules/navigation_mesh_generator/register_types.h @@ -0,0 +1,39 @@ +/*************************************************************************/ +/* register_types.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef NAVIGATION_MESH_GENERATOR_REGISTER_TYPES_H +#define NAVIGATION_MESH_GENERATOR_REGISTER_TYPES_H + +#include "modules/register_module_types.h" + +void initialize_navigation_mesh_generator_module(ModuleInitializationLevel p_level); +void uninitialize_navigation_mesh_generator_module(ModuleInitializationLevel p_level); + +#endif // NAVIGATION_MESH_GENERATOR_REGISTER_TYPES_H diff --git a/scene/3d/navigation_region_3d.cpp b/scene/3d/navigation_region_3d.cpp index 86b78f847e78..cf8a9c368983 100644 --- a/scene/3d/navigation_region_3d.cpp +++ b/scene/3d/navigation_region_3d.cpp @@ -33,6 +33,10 @@ #include "mesh_instance_3d.h" #include "servers/navigation_server_3d.h" +#ifdef MODULE_NAVIGATION_MESH_GENERATOR_ENABLED +#include "modules/navigation_mesh_generator/navigation_mesh_generator.h" +#endif // MODULE_NAVIGATION_MESH_GENERATOR_ENABLED + void NavigationRegion3D::set_enabled(bool p_enabled) { if (enabled == p_enabled) { return; @@ -235,6 +239,7 @@ Ref NavigationRegion3D::get_navigation_mesh() const { return navigation_mesh; } +#ifdef MODULE_NAVIGATION_MESH_GENERATOR_ENABLED struct BakeThreadsArgs { NavigationRegion3D *nav_region = nullptr; }; @@ -245,7 +250,9 @@ void _bake_navigation_mesh(void *p_user_data) { if (args->nav_region->get_navigation_mesh().is_valid()) { Ref nav_mesh = args->nav_region->get_navigation_mesh()->duplicate(); - NavigationServer3D::get_singleton()->region_bake_navigation_mesh(nav_mesh, args->nav_region); + NavigationMeshGenerator::get_singleton()->clear(nav_mesh); + NavigationMeshGenerator::get_singleton()->bake(nav_mesh, args->nav_region); + args->nav_region->call_deferred(SNAME("_bake_finished"), nav_mesh); memdelete(args); } else { @@ -254,8 +261,10 @@ void _bake_navigation_mesh(void *p_user_data) { memdelete(args); } } +#endif // MODULE_NAVIGATION_MESH_GENERATOR_ENABLED void NavigationRegion3D::bake_navigation_mesh(bool p_on_thread) { +#ifdef MODULE_NAVIGATION_MESH_GENERATOR_ENABLED ERR_FAIL_COND_MSG(bake_thread.is_started(), "Unable to start another bake request. The navigation mesh bake thread is already baking a navigation mesh."); BakeThreadsArgs *args = memnew(BakeThreadsArgs); @@ -266,12 +275,27 @@ void NavigationRegion3D::bake_navigation_mesh(bool p_on_thread) { } else { _bake_navigation_mesh(args); } +#endif // MODULE_NAVIGATION_MESH_GENERATOR_ENABLED + +#ifndef MODULE_NAVIGATION_MESH_GENERATOR_ENABLED +#ifdef DEBUG_ENABLED + WARN_PRINT_ONCE("bake_navigation_mesh() is only functional in builds with NavigationMeshGenerator module enabled."); +#endif // DEBUG_ENABLED +#endif // MODULE_NAVIGATION_MESH_GENERATOR_ENABLED } void NavigationRegion3D::_bake_finished(Ref p_nav_mesh) { +#ifdef MODULE_NAVIGATION_MESH_GENERATOR_ENABLED set_navigation_mesh(p_nav_mesh); bake_thread.wait_to_finish(); emit_signal(SNAME("bake_finished")); +#endif // MODULE_NAVIGATION_MESH_GENERATOR_ENABLED + +#ifndef MODULE_NAVIGATION_MESH_GENERATOR_ENABLED +#ifdef DEBUG_ENABLED + WARN_PRINT_ONCE("_bake_finished() is only functional in builds with NavigationMeshGenerator module enabled."); +#endif // DEBUG_ENABLED +#endif // MODULE_NAVIGATION_MESH_GENERATOR_ENABLED } PackedStringArray NavigationRegion3D::get_configuration_warnings() const { diff --git a/servers/navigation_server_3d.cpp b/servers/navigation_server_3d.cpp index 6ad07d3053ef..fac71156afdd 100644 --- a/servers/navigation_server_3d.cpp +++ b/servers/navigation_server_3d.cpp @@ -78,7 +78,6 @@ void NavigationServer3D::_bind_methods() { ClassDB::bind_method(D_METHOD("region_get_navigation_layers", "region"), &NavigationServer3D::region_get_navigation_layers); ClassDB::bind_method(D_METHOD("region_set_transform", "region", "transform"), &NavigationServer3D::region_set_transform); ClassDB::bind_method(D_METHOD("region_set_navigation_mesh", "region", "navigation_mesh"), &NavigationServer3D::region_set_navigation_mesh); - ClassDB::bind_method(D_METHOD("region_bake_navigation_mesh", "navigation_mesh", "root_node"), &NavigationServer3D::region_bake_navigation_mesh); ClassDB::bind_method(D_METHOD("region_get_connections_count", "region"), &NavigationServer3D::region_get_connections_count); ClassDB::bind_method(D_METHOD("region_get_connection_pathway_start", "region", "connection"), &NavigationServer3D::region_get_connection_pathway_start); ClassDB::bind_method(D_METHOD("region_get_connection_pathway_end", "region", "connection"), &NavigationServer3D::region_get_connection_pathway_end); diff --git a/servers/navigation_server_3d.h b/servers/navigation_server_3d.h index 65d6d19073c7..952c75200c36 100644 --- a/servers/navigation_server_3d.h +++ b/servers/navigation_server_3d.h @@ -140,9 +140,6 @@ class NavigationServer3D : public Object { /// Set the navigation mesh of this region. virtual void region_set_navigation_mesh(RID p_region, Ref p_navigation_mesh) const = 0; - /// Bake the navigation mesh. - virtual void region_bake_navigation_mesh(Ref p_navigation_mesh, Node *p_root_node) const = 0; - /// Get a list of a region's connection to other regions. virtual int region_get_connections_count(RID p_region) const = 0; virtual Vector3 region_get_connection_pathway_start(RID p_region, int p_connection_id) const = 0;