From 2296bf693a70e1f52417f14f4dbe1fa77389d26e Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 5 Jun 2023 20:42:35 +0200 Subject: [PATCH] Fix and finally enable PandemoniumNavigationMeshGenerator. --- modules/navigation_mesh_generator/SCsub | 49 ++++++++++--------- modules/navigation_mesh_generator/config.py | 5 +- .../pandemonium_navigation_mesh_generator.cpp | 36 +++++++------- .../pandemonium_navigation_mesh_generator.h | 8 +-- scene/resources/navigation_mesh.cpp | 6 +-- scene/resources/navigation_mesh.h | 2 +- 6 files changed, 57 insertions(+), 49 deletions(-) diff --git a/modules/navigation_mesh_generator/SCsub b/modules/navigation_mesh_generator/SCsub index 448062dbc..642aaf8c7 100644 --- a/modules/navigation_mesh_generator/SCsub +++ b/modules/navigation_mesh_generator/SCsub @@ -7,42 +7,45 @@ env_navigation_mesh_generator = env_modules.Clone() # Thirdparty source files -thirdparty_obj = [] +#thirdparty_obj = [] # Recast Thirdparty source files -if env["builtin_recastnavigation"]: +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] + + #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_thirdparty = env_navigation_mesh_generator.Clone() + #env_thirdparty.disable_warnings() + #env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources) -env.modules_sources += thirdparty_obj +#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") + +#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) +#env.Depends(module_obj, thirdparty_obj) diff --git a/modules/navigation_mesh_generator/config.py b/modules/navigation_mesh_generator/config.py index 0aef4f28b..2afaa70ea 100644 --- a/modules/navigation_mesh_generator/config.py +++ b/modules/navigation_mesh_generator/config.py @@ -1,8 +1,9 @@ def can_build(env, platform): - #return True - return False + env.module_add_dependencies("navigation_mesh_generator", ["navigation"], False) + + return True def configure(env): diff --git a/modules/navigation_mesh_generator/pandemonium_navigation_mesh_generator.cpp b/modules/navigation_mesh_generator/pandemonium_navigation_mesh_generator.cpp index fe4eb3b8f..e0ea01307 100644 --- a/modules/navigation_mesh_generator/pandemonium_navigation_mesh_generator.cpp +++ b/modules/navigation_mesh_generator/pandemonium_navigation_mesh_generator.cpp @@ -200,7 +200,7 @@ void PandemoniumNavigationMeshGenerator::_process_2d_parse_tasks() { } void PandemoniumNavigationMeshGenerator::_process_2d_bake_cleanup_tasks() { - for (int i = 0; i < _2d_running_jobs.size(); ++i) { + for (uint32_t i = 0; i < _2d_running_jobs.size(); ++i) { Ref &e = _2d_running_jobs[i]; if (e->get_complete()) { @@ -298,8 +298,8 @@ void PandemoniumNavigationMeshGenerator::_static_parse_2d_source_geometry_data(R p_source_geometry_data->clear(); p_source_geometry_data->root_node_transform = root_node_transform; - for (Node *E : parse_nodes) { - _static_parse_2d_geometry_node(p_navigation_polygon, E, p_source_geometry_data, recurse_children, p_geometry_2d_parsers); + for (List::Element *E = parse_nodes.front(); E; E = E->next()) { + _static_parse_2d_geometry_node(p_navigation_polygon, E->get(), p_source_geometry_data, recurse_children, p_geometry_2d_parsers); } } @@ -608,7 +608,7 @@ void PandemoniumNavigationMeshGenerator::_process_3d_parse_tasks() { } void PandemoniumNavigationMeshGenerator::_process_3d_bake_cleanup_tasks() { - for (int i = 0; i < _3d_running_jobs.size(); ++i) { + for (uint32_t i = 0; i < _3d_running_jobs.size(); ++i) { Ref &e = _3d_running_jobs[i]; if (e->get_complete()) { @@ -629,8 +629,8 @@ void PandemoniumNavigationMeshGenerator::_static_bake_3d_from_source_geometry_da } #ifndef _3D_DISABLED - const Vector vertices = p_source_geometry_data->get_vertices(); - const Vector indices = p_source_geometry_data->get_indices(); + PoolRealArray vertices = p_source_geometry_data->get_vertices(); + PoolIntArray indices = p_source_geometry_data->get_indices(); if (vertices.size() < 3 || indices.size() < 3) { return; @@ -648,9 +648,11 @@ void PandemoniumNavigationMeshGenerator::_static_bake_3d_from_source_geometry_da bake_state = "Setting up Configuration..."; // step #1 - const float *verts = vertices.ptr(); + PoolRealArray::Read vertices_read = vertices.read(); + PoolIntArray::Read indices_read = indices.read(); + const float *verts = vertices_read.ptr(); const int nverts = vertices.size() / 3; - const int *tris = indices.ptr(); + const int *tris = indices_read.ptr(); const int ntris = indices.size() / 3; float bmin[3], bmax[3]; @@ -669,7 +671,7 @@ void PandemoniumNavigationMeshGenerator::_static_bake_3d_from_source_geometry_da cfg.maxSimplificationError = p_navigation_mesh->get_edge_max_error(); cfg.minRegionArea = (int)(p_navigation_mesh->get_region_min_size() * p_navigation_mesh->get_region_min_size()); cfg.mergeRegionArea = (int)(p_navigation_mesh->get_region_merge_size() * p_navigation_mesh->get_region_merge_size()); - cfg.maxVertsPerPoly = (int)p_navigation_mesh->get_vertices_per_polygon(); + cfg.maxVertsPerPoly = (int)p_navigation_mesh->get_verts_per_poly(); cfg.detailSampleDist = MAX(p_navigation_mesh->get_cell_size() * p_navigation_mesh->get_detail_sample_distance(), 0.1f); cfg.detailSampleMaxError = p_navigation_mesh->get_cell_height() * p_navigation_mesh->get_detail_sample_max_error(); @@ -681,7 +683,7 @@ void PandemoniumNavigationMeshGenerator::_static_bake_3d_from_source_geometry_da cfg.bmax[2] = bmax[2]; AABB baking_aabb = p_navigation_mesh->get_filter_baking_aabb(); - if (baking_aabb.has_volume()) { + if (!baking_aabb.has_no_volume()) { Vector3 baking_aabb_offset = p_navigation_mesh->get_filter_baking_aabb_offset(); cfg.bmin[0] = baking_aabb.position[0] + baking_aabb_offset.x; cfg.bmin[1] = baking_aabb.position[1] + baking_aabb_offset.y; @@ -775,7 +777,7 @@ void PandemoniumNavigationMeshGenerator::_static_bake_3d_from_source_geometry_da bake_state = "Converting to native navigation mesh..."; // step #10 - Vector new_navigation_mesh_vertices; + PoolVector new_navigation_mesh_vertices; Vector> new_navigation_mesh_polygons; for (int i = 0; i < detail_mesh->nverts; i++) { @@ -801,7 +803,7 @@ void PandemoniumNavigationMeshGenerator::_static_bake_3d_from_source_geometry_da } p_navigation_mesh->set_vertices(new_navigation_mesh_vertices); - p_navigation_mesh->internal_set_polygons(new_navigation_mesh_polygons); + p_navigation_mesh->set_polygons(new_navigation_mesh_polygons); bake_state = "Cleanup..."; // step #11 @@ -831,11 +833,11 @@ void PandemoniumNavigationMeshGenerator::_static_bake_3d_from_source_geometry_da } void PandemoniumNavigationMeshGenerator::parse_and_bake_3d(Ref p_navigation_mesh, Node *p_root_node, Ref p_callback) { - ERR_FAIL_COND_MSG(baking_navmeshes.find(p_navigation_mesh) >= 0, "NavigationMesh was already added to baking queue. Wait for current bake task to finish."); + ERR_FAIL_COND_MSG(_baking_navmeshes.find(p_navigation_mesh) >= 0, "NavigationMesh was already added to baking queue. Wait for current bake task to finish."); ERR_FAIL_COND_MSG(p_root_node == nullptr, "avigationMesh requires a valid root node."); _generator_mutex.lock(); - baking_navmeshes.push_back(p_navigation_mesh); + _baking_navmeshes.push_back(p_navigation_mesh); _generator_mutex.unlock(); Ref navigation_generator_task; @@ -882,7 +884,7 @@ Ref PandemoniumNavigationMeshGenerator::pars Ref source_geometry_data = Ref(memnew(NavigationMeshSourceGeometryData3D)); - _static_parse_3d_source_geometry_data(p_navigation_mesh, p_root_node, source_geometry_data, geometry_3d_parsers); + _static_parse_3d_source_geometry_data(p_navigation_mesh, p_root_node, source_geometry_data, _geometry_3d_parsers); return source_geometry_data; }; @@ -942,8 +944,8 @@ void PandemoniumNavigationMeshGenerator::_static_parse_3d_source_geometry_data(R p_source_geometry_data->clear(); p_source_geometry_data->root_node_transform = root_node_transform; - for (Node *E : parse_nodes) { - _static_parse_3d_geometry_node(p_navigation_mesh, E, p_source_geometry_data, recurse_children, p_geometry_3d_parsers); + for (List::Element *E = parse_nodes.front(); E; E = E->next()) { + _static_parse_3d_geometry_node(p_navigation_mesh, E->get(), p_source_geometry_data, recurse_children, p_geometry_3d_parsers); } } #endif // _3D_DISABLED diff --git a/modules/navigation_mesh_generator/pandemonium_navigation_mesh_generator.h b/modules/navigation_mesh_generator/pandemonium_navigation_mesh_generator.h index 0712ff3e2..bcc47b822 100644 --- a/modules/navigation_mesh_generator/pandemonium_navigation_mesh_generator.h +++ b/modules/navigation_mesh_generator/pandemonium_navigation_mesh_generator.h @@ -45,6 +45,8 @@ class NavigationMeshSourceGeometryData3D; class NavigationGeometryParser3D; class PandemoniumNavigationMeshGenerator : public NavigationMeshGenerator { + GDCLASS(PandemoniumNavigationMeshGenerator, NavigationMeshGenerator); + public: // ======= TASKS ======= @@ -145,6 +147,9 @@ public: virtual bool is_navigation_mesh_baking(Ref p_navigation_mesh) const; #endif // _3D_DISABLED + PandemoniumNavigationMeshGenerator(); + ~PandemoniumNavigationMeshGenerator(); + private: void _process_2d_tasks(); void _process_2d_parse_tasks(); @@ -156,9 +161,6 @@ private: void _process_3d_bake_cleanup_tasks(); #endif // _3D_DISABLED - PandemoniumNavigationMeshGenerator(); - ~PandemoniumNavigationMeshGenerator(); - private: Mutex _generator_mutex; diff --git a/scene/resources/navigation_mesh.cpp b/scene/resources/navigation_mesh.cpp index 7fce675b8..ca934a68f 100644 --- a/scene/resources/navigation_mesh.cpp +++ b/scene/resources/navigation_mesh.cpp @@ -618,7 +618,7 @@ void NavigationMesh::_bind_methods() { BIND_ENUM_CONSTANT(PARSED_GEOMETRY_BOTH); BIND_ENUM_CONSTANT(PARSED_GEOMETRY_MAX); - BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_NAVMESH_CHILDREN); + BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_ROOT_NODE_CHILDREN); BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN); BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_GROUPS_EXPLICIT); BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_MAX); @@ -633,7 +633,7 @@ void NavigationMesh::_validate_property(PropertyInfo &property) const { } if (property.name == "geometry/source_group_name") { - if (source_geometry_mode == SOURCE_GEOMETRY_NAVMESH_CHILDREN) { + if (source_geometry_mode == SOURCE_GEOMETRY_ROOT_NODE_CHILDREN) { property.usage = 0; return; } @@ -658,7 +658,7 @@ NavigationMesh::NavigationMesh() { partition_type = SAMPLE_PARTITION_WATERSHED; parsed_geometry_type = PARSED_GEOMETRY_MESH_INSTANCES; collision_mask = 0xFFFFFFFF; - source_geometry_mode = SOURCE_GEOMETRY_NAVMESH_CHILDREN; + source_geometry_mode = SOURCE_GEOMETRY_ROOT_NODE_CHILDREN; source_group_name = "navmesh"; filter_low_hanging_obstacles = false; filter_ledge_spans = false; diff --git a/scene/resources/navigation_mesh.h b/scene/resources/navigation_mesh.h index ee2768a0e..e0d5f102f 100644 --- a/scene/resources/navigation_mesh.h +++ b/scene/resources/navigation_mesh.h @@ -56,7 +56,7 @@ public: }; enum SourceGeometryMode { - SOURCE_GEOMETRY_NAVMESH_CHILDREN = 0, + SOURCE_GEOMETRY_ROOT_NODE_CHILDREN = 0, SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN, SOURCE_GEOMETRY_GROUPS_EXPLICIT, SOURCE_GEOMETRY_MAX