From b96e013bed474da66422066e6663dcada33f5d83 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 6 Jun 2023 07:48:19 +0200 Subject: [PATCH] Updated navigation geometry parsers, and added them to the build. --- modules/navigation_geometry_parsers/SCsub | 4 +- modules/navigation_geometry_parsers/config.py | 2 + ...instance2d_navigation_geometry_parser_2d.h | 4 +- ...instance2d_navigation_geometry_parser_2d.h | 4 +- ...olygon2d_navigation_geometry_parser_2d.cpp | 8 ++- .../polygon2d_navigation_geometry_parser_2d.h | 4 +- ...icbody2d_navigation_geometry_parser_2d.cpp | 41 +++++++---- ...aticbody2d_navigation_geometry_parser_2d.h | 4 +- .../tilemap_navigation_geometry_parser_2d.cpp | 8 ++- .../tilemap_navigation_geometry_parser_2d.h | 4 +- ...stance3d_navigation_geometry_parser_3d.cpp | 11 +-- ...instance3d_navigation_geometry_parser_3d.h | 4 +- ...stance3d_navigation_geometry_parser_3d.cpp | 12 ++-- ...instance3d_navigation_geometry_parser_3d.h | 4 +- ...icbody3d_navigation_geometry_parser_3d.cpp | 71 +++++++++++-------- ...aticbody3d_navigation_geometry_parser_3d.h | 4 +- .../register_types.cpp | 23 ++++++ .../pandemonium_navigation_mesh_generator.cpp | 14 ---- 18 files changed, 137 insertions(+), 89 deletions(-) diff --git a/modules/navigation_geometry_parsers/SCsub b/modules/navigation_geometry_parsers/SCsub index 32e337bd4..53a8a35b9 100644 --- a/modules/navigation_geometry_parsers/SCsub +++ b/modules/navigation_geometry_parsers/SCsub @@ -10,7 +10,7 @@ env_navigation = env_modules.Clone() module_obj = [] env_navigation.add_source_files(module_obj, "*.cpp") -#env_navigation.add_source_files(module_obj, "geometry_parser_2d/*.cpp") -#env_navigation.add_source_files(module_obj, "geometry_parser_3d/*.cpp") +env_navigation.add_source_files(module_obj, "geometry_parser_2d/*.cpp") +env_navigation.add_source_files(module_obj, "geometry_parser_3d/*.cpp") env.modules_sources += module_obj diff --git a/modules/navigation_geometry_parsers/config.py b/modules/navigation_geometry_parsers/config.py index c6f699c9d..e48766d83 100644 --- a/modules/navigation_geometry_parsers/config.py +++ b/modules/navigation_geometry_parsers/config.py @@ -1,5 +1,7 @@ def can_build(env, platform): + env.module_add_dependencies("navigation_geometry_parsers", ["navigation_mesh_generator"], False) + return True diff --git a/modules/navigation_geometry_parsers/geometry_parser_2d/meshinstance2d_navigation_geometry_parser_2d.h b/modules/navigation_geometry_parsers/geometry_parser_2d/meshinstance2d_navigation_geometry_parser_2d.h index fb7c5534a..a62f25f1b 100644 --- a/modules/navigation_geometry_parsers/geometry_parser_2d/meshinstance2d_navigation_geometry_parser_2d.h +++ b/modules/navigation_geometry_parsers/geometry_parser_2d/meshinstance2d_navigation_geometry_parser_2d.h @@ -35,9 +35,9 @@ class MeshInstance2DNavigationGeometryParser2D : public NavigationGeometryParser2D { public: - virtual bool parses_node(Node *p_node) override; + virtual bool parses_node(Node *p_node) ; - virtual void parse_geometry(Node *p_node, Ref p_navigation_polygon, Ref p_source_geometry) override; + virtual void parse_geometry(Node *p_node, Ref p_navigation_polygon, Ref p_source_geometry) ; }; #endif // MESHINSTANCE2D_NAVIGATION_GEOMETRY_PARSER_2D_H diff --git a/modules/navigation_geometry_parsers/geometry_parser_2d/multimeshinstance2d_navigation_geometry_parser_2d.h b/modules/navigation_geometry_parsers/geometry_parser_2d/multimeshinstance2d_navigation_geometry_parser_2d.h index 453963dda..b68791523 100644 --- a/modules/navigation_geometry_parsers/geometry_parser_2d/multimeshinstance2d_navigation_geometry_parser_2d.h +++ b/modules/navigation_geometry_parsers/geometry_parser_2d/multimeshinstance2d_navigation_geometry_parser_2d.h @@ -35,9 +35,9 @@ class MultiMeshInstance2DNavigationGeometryParser2D : public NavigationGeometryParser2D { public: - virtual bool parses_node(Node *p_node) override; + virtual bool parses_node(Node *p_node) ; - virtual void parse_geometry(Node *p_node, Ref p_navigation_polygon, Ref p_source_geometry) override; + virtual void parse_geometry(Node *p_node, Ref p_navigation_polygon, Ref p_source_geometry) ; }; #endif // MULTIMESHINSTANCE2D_NAVIGATION_GEOMETRY_PARSER_2D_H diff --git a/modules/navigation_geometry_parsers/geometry_parser_2d/polygon2d_navigation_geometry_parser_2d.cpp b/modules/navigation_geometry_parsers/geometry_parser_2d/polygon2d_navigation_geometry_parser_2d.cpp index 362db68a3..475195a64 100644 --- a/modules/navigation_geometry_parsers/geometry_parser_2d/polygon2d_navigation_geometry_parser_2d.cpp +++ b/modules/navigation_geometry_parsers/geometry_parser_2d/polygon2d_navigation_geometry_parser_2d.cpp @@ -32,6 +32,9 @@ #include "scene/2d/polygon_2d.h" +#include "scene/resources/navigation_mesh_source_geometry_data_2d.h" +#include "scene/resources/navigation_polygon.h" + bool Polygon2DNavigationGeometryParser2D::parses_node(Node *p_node) { return (Object::cast_to(p_node) != nullptr); } @@ -44,9 +47,10 @@ void Polygon2DNavigationGeometryParser2D::parse_geometry(Node *p_node, Refget_global_transform(); - Vector shape_outline = polygon_2d->get_polygon(); + PoolVector shape_outline = polygon_2d->get_polygon(); + PoolVector::Write shape_outline_write = shape_outline.write(); for (int i = 0; i < shape_outline.size(); i++) { - shape_outline.write[i] = transform.xform(shape_outline[i]); + shape_outline_write[i] = transform.xform(shape_outline[i]); } p_source_geometry->add_obstruction_outline(shape_outline); diff --git a/modules/navigation_geometry_parsers/geometry_parser_2d/polygon2d_navigation_geometry_parser_2d.h b/modules/navigation_geometry_parsers/geometry_parser_2d/polygon2d_navigation_geometry_parser_2d.h index 017e1b470..af523d67d 100644 --- a/modules/navigation_geometry_parsers/geometry_parser_2d/polygon2d_navigation_geometry_parser_2d.h +++ b/modules/navigation_geometry_parsers/geometry_parser_2d/polygon2d_navigation_geometry_parser_2d.h @@ -35,9 +35,9 @@ class Polygon2DNavigationGeometryParser2D : public NavigationGeometryParser2D { public: - virtual bool parses_node(Node *p_node) override; + virtual bool parses_node(Node *p_node); - virtual void parse_geometry(Node *p_node, Ref p_navigation_polygon, Ref p_source_geometry) override; + virtual void parse_geometry(Node *p_node, Ref p_navigation_polygon, Ref p_source_geometry); }; #endif // POLYGON2D_NAVIGATION_GEOMETRY_PARSER_2D_H diff --git a/modules/navigation_geometry_parsers/geometry_parser_2d/staticbody2d_navigation_geometry_parser_2d.cpp b/modules/navigation_geometry_parsers/geometry_parser_2d/staticbody2d_navigation_geometry_parser_2d.cpp index 00cc99565..bca7dd2fd 100644 --- a/modules/navigation_geometry_parsers/geometry_parser_2d/staticbody2d_navigation_geometry_parser_2d.cpp +++ b/modules/navigation_geometry_parsers/geometry_parser_2d/staticbody2d_navigation_geometry_parser_2d.cpp @@ -40,6 +40,9 @@ #include "scene/resources/rectangle_shape_2d.h" #include "scene/resources/shape_2d.h" +#include "scene/resources/navigation_mesh_source_geometry_data_2d.h" +#include "scene/resources/navigation_polygon.h" + bool StaticBody2DNavigationGeometryParser2D::parses_node(Node *p_node) { return (Object::cast_to(p_node) != nullptr); } @@ -53,7 +56,10 @@ void StaticBody2DNavigationGeometryParser2D::parse_geometry(Node *p_node, Refget_collision_layer() & navigation_polygon_collision_mask) { List shape_owners; static_body->get_shape_owners(&shape_owners); - for (uint32_t shape_owner : shape_owners) { + + for (List::Element *E = shape_owners.front(); E; E = E->next()) { + uint32_t shape_owner = E->get(); + if (static_body->is_shape_owner_disabled(shape_owner)) { continue; } @@ -69,16 +75,17 @@ void StaticBody2DNavigationGeometryParser2D::parse_geometry(Node *p_node, Ref(*s); if (rectangle_shape) { - Vector shape_outline; + PoolVector shape_outline; - const Vector2 &rectangle_size = rectangle_shape->get_size(); + const Vector2 rectangle_size = rectangle_shape->get_extents(); shape_outline.resize(5); - shape_outline.write[0] = transform.xform(-rectangle_size * 0.5); - shape_outline.write[1] = transform.xform(Vector2(rectangle_size.x, -rectangle_size.y) * 0.5); - shape_outline.write[2] = transform.xform(rectangle_size * 0.5); - shape_outline.write[3] = transform.xform(Vector2(-rectangle_size.x, rectangle_size.y) * 0.5); - shape_outline.write[4] = transform.xform(-rectangle_size * 0.5); + PoolVector::Write shape_outline_write = shape_outline.write(); + shape_outline_write[0] = transform.xform(-rectangle_size * 0.5); + shape_outline_write[1] = transform.xform(Vector2(rectangle_size.x, -rectangle_size.y) * 0.5); + shape_outline_write[2] = transform.xform(rectangle_size * 0.5); + shape_outline_write[3] = transform.xform(Vector2(-rectangle_size.x, rectangle_size.y) * 0.5); + shape_outline_write[4] = transform.xform(-rectangle_size * 0.5); p_source_geometry->add_obstruction_outline(shape_outline); } @@ -93,13 +100,14 @@ void StaticBody2DNavigationGeometryParser2D::parse_geometry(Node *p_node, Ref(*s); if (circle_shape) { - Vector shape_outline; + PoolVector shape_outline; int circle_edge_count = 12; shape_outline.resize(circle_edge_count); + PoolVector::Write shape_outline_write = shape_outline.write(); const real_t turn_step = Math_TAU / real_t(circle_edge_count); for (int i = 0; i < circle_edge_count; i++) { - shape_outline.write[i] = transform.xform(Vector2(Math::cos(i * turn_step), Math::sin(i * turn_step)) * circle_shape->get_radius()); + shape_outline_write[i] = transform.xform(Vector2(Math::cos(i * turn_step), Math::sin(i * turn_step)) * circle_shape->get_radius()); } p_source_geometry->add_obstruction_outline(shape_outline); @@ -107,10 +115,11 @@ void StaticBody2DNavigationGeometryParser2D::parse_geometry(Node *p_node, Ref(*s); if (concave_polygon_shape) { - Vector shape_outline = concave_polygon_shape->get_segments(); + PoolVector shape_outline = concave_polygon_shape->get_segments(); + PoolVector::Write shape_outline_write = shape_outline.write(); for (int i = 0; i < shape_outline.size(); i++) { - shape_outline.write[i] = transform.xform(shape_outline[i]); + shape_outline_write[i] = transform.xform(shape_outline[i]); } p_source_geometry->add_obstruction_outline(shape_outline); @@ -118,10 +127,14 @@ void StaticBody2DNavigationGeometryParser2D::parse_geometry(Node *p_node, Ref(*s); if (convex_polygon_shape) { - Vector shape_outline = convex_polygon_shape->get_points(); + Vector shape_outlinev = convex_polygon_shape->get_points(); + + PoolVector shape_outline; + shape_outline.resize(shape_outlinev.size()); + PoolVector::Write shape_outline_write = shape_outline.write(); for (int i = 0; i < shape_outline.size(); i++) { - shape_outline.write[i] = transform.xform(shape_outline[i]); + shape_outline_write[i] = transform.xform(shape_outlinev[i]); } p_source_geometry->add_obstruction_outline(shape_outline); diff --git a/modules/navigation_geometry_parsers/geometry_parser_2d/staticbody2d_navigation_geometry_parser_2d.h b/modules/navigation_geometry_parsers/geometry_parser_2d/staticbody2d_navigation_geometry_parser_2d.h index 8e7af2596..6aa154a1f 100644 --- a/modules/navigation_geometry_parsers/geometry_parser_2d/staticbody2d_navigation_geometry_parser_2d.h +++ b/modules/navigation_geometry_parsers/geometry_parser_2d/staticbody2d_navigation_geometry_parser_2d.h @@ -35,9 +35,9 @@ class StaticBody2DNavigationGeometryParser2D : public NavigationGeometryParser2D { public: - virtual bool parses_node(Node *p_node) override; + virtual bool parses_node(Node *p_node); - virtual void parse_geometry(Node *p_node, Ref p_navigation_polygon, Ref p_source_geometry) override; + virtual void parse_geometry(Node *p_node, Ref p_navigation_polygon, Ref p_source_geometry); }; #endif // STATICBODY2D_NAVIGATION_GEOMETRY_PARSER_2D_H diff --git a/modules/navigation_geometry_parsers/geometry_parser_2d/tilemap_navigation_geometry_parser_2d.cpp b/modules/navigation_geometry_parsers/geometry_parser_2d/tilemap_navigation_geometry_parser_2d.cpp index 626311ec9..3e8ae8a53 100644 --- a/modules/navigation_geometry_parsers/geometry_parser_2d/tilemap_navigation_geometry_parser_2d.cpp +++ b/modules/navigation_geometry_parsers/geometry_parser_2d/tilemap_navigation_geometry_parser_2d.cpp @@ -30,14 +30,18 @@ #include "tilemap_navigation_geometry_parser_2d.h" -#include "scene/2d/tile_map.h" +//#include "scene/2d/tile_map.h" + +#include "scene/resources/navigation_polygon.h" +#include "scene/resources/navigation_mesh_source_geometry_data_2d.h" #ifdef CLIPPER_ENABLED #include "thirdparty/clipper2/include/clipper2/clipper.h" #endif // CLIPPER_ENABLED bool TileMap2DNavigationGeometryParser2D::parses_node(Node *p_node) { - return (Object::cast_to(p_node) != nullptr); + //return (Object::cast_to(p_node) != nullptr); + return false; } void TileMap2DNavigationGeometryParser2D::parse_geometry(Node *p_node, Ref p_navigation_polygon, Ref p_source_geometry) { diff --git a/modules/navigation_geometry_parsers/geometry_parser_2d/tilemap_navigation_geometry_parser_2d.h b/modules/navigation_geometry_parsers/geometry_parser_2d/tilemap_navigation_geometry_parser_2d.h index cba1e3671..3acb156f0 100644 --- a/modules/navigation_geometry_parsers/geometry_parser_2d/tilemap_navigation_geometry_parser_2d.h +++ b/modules/navigation_geometry_parsers/geometry_parser_2d/tilemap_navigation_geometry_parser_2d.h @@ -35,9 +35,9 @@ class TileMap2DNavigationGeometryParser2D : public NavigationGeometryParser2D { public: - virtual bool parses_node(Node *p_node) override; + virtual bool parses_node(Node *p_node); - virtual void parse_geometry(Node *p_node, Ref p_navigation_polygon, Ref p_source_geometry) override; + virtual void parse_geometry(Node *p_node, Ref p_navigation_polygon, Ref p_source_geometry); }; #endif // TILEMAP_NAVIGATION_GEOMETRY_PARSER_2D_H diff --git a/modules/navigation_geometry_parsers/geometry_parser_3d/meshinstance3d_navigation_geometry_parser_3d.cpp b/modules/navigation_geometry_parsers/geometry_parser_3d/meshinstance3d_navigation_geometry_parser_3d.cpp index 264308898..ac6851397 100644 --- a/modules/navigation_geometry_parsers/geometry_parser_3d/meshinstance3d_navigation_geometry_parser_3d.cpp +++ b/modules/navigation_geometry_parsers/geometry_parser_3d/meshinstance3d_navigation_geometry_parser_3d.cpp @@ -30,17 +30,20 @@ #include "meshinstance3d_navigation_geometry_parser_3d.h" -#include "scene/3d/mesh_instance_3d.h" +#include "scene/3d/mesh_instance.h" +#include "scene/resources/mesh.h" +#include "scene/resources/navigation_mesh.h" +#include "scene/resources/navigation_mesh_source_geometry_data_3d.h" bool MeshInstance3DNavigationGeometryParser3D::parses_node(Node *p_node) { - return (Object::cast_to(p_node) != nullptr); + return (Object::cast_to(p_node) != nullptr); } void MeshInstance3DNavigationGeometryParser3D::parse_geometry(Node *p_node, Ref p_navigationmesh, Ref p_source_geometry) { NavigationMesh::ParsedGeometryType parsed_geometry_type = p_navigationmesh->get_parsed_geometry_type(); - if (Object::cast_to(p_node) && parsed_geometry_type != NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS) { - MeshInstance3D *mesh_instance = Object::cast_to(p_node); + if (Object::cast_to(p_node) && parsed_geometry_type != NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS) { + MeshInstance *mesh_instance = Object::cast_to(p_node); Ref mesh = mesh_instance->get_mesh(); if (mesh.is_valid()) { p_source_geometry->add_mesh(mesh, mesh_instance->get_global_transform()); diff --git a/modules/navigation_geometry_parsers/geometry_parser_3d/meshinstance3d_navigation_geometry_parser_3d.h b/modules/navigation_geometry_parsers/geometry_parser_3d/meshinstance3d_navigation_geometry_parser_3d.h index 9e50d9401..d37237400 100644 --- a/modules/navigation_geometry_parsers/geometry_parser_3d/meshinstance3d_navigation_geometry_parser_3d.h +++ b/modules/navigation_geometry_parsers/geometry_parser_3d/meshinstance3d_navigation_geometry_parser_3d.h @@ -35,9 +35,9 @@ class MeshInstance3DNavigationGeometryParser3D : public NavigationGeometryParser3D { public: - virtual bool parses_node(Node *p_node) override; + virtual bool parses_node(Node *p_node); - virtual void parse_geometry(Node *p_node, Ref p_navigationmesh, Ref p_source_geometry) override; + virtual void parse_geometry(Node *p_node, Ref p_navigationmesh, Ref p_source_geometry); }; #endif // MESHINSTANCE3D_NAVIGATION_GEOMETRY_PARSER_3D_H diff --git a/modules/navigation_geometry_parsers/geometry_parser_3d/multimeshinstance3d_navigation_geometry_parser_3d.cpp b/modules/navigation_geometry_parsers/geometry_parser_3d/multimeshinstance3d_navigation_geometry_parser_3d.cpp index 6a934bfc8..34f426b5f 100644 --- a/modules/navigation_geometry_parsers/geometry_parser_3d/multimeshinstance3d_navigation_geometry_parser_3d.cpp +++ b/modules/navigation_geometry_parsers/geometry_parser_3d/multimeshinstance3d_navigation_geometry_parser_3d.cpp @@ -30,17 +30,21 @@ #include "multimeshinstance3d_navigation_geometry_parser_3d.h" -#include "scene/3d/multimesh_instance_3d.h" +#include "scene/3d/multimesh_instance.h" +#include "scene/resources/mesh.h" +#include "scene/resources/multimesh.h" +#include "scene/resources/navigation_mesh.h" +#include "scene/resources/navigation_mesh_source_geometry_data_3d.h" bool MultiMeshInstance3DNavigationGeometryParser3D::parses_node(Node *p_node) { - return (Object::cast_to(p_node) != nullptr); + return (Object::cast_to(p_node) != nullptr); } void MultiMeshInstance3DNavigationGeometryParser3D::parse_geometry(Node *p_node, Ref p_navigationmesh, Ref p_source_geometry) { NavigationMesh::ParsedGeometryType parsed_geometry_type = p_navigationmesh->get_parsed_geometry_type(); - if (Object::cast_to(p_node) && parsed_geometry_type != NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS) { - MultiMeshInstance3D *multimesh_instance = Object::cast_to(p_node); + if (Object::cast_to(p_node) && parsed_geometry_type != NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS) { + MultiMeshInstance *multimesh_instance = Object::cast_to(p_node); Ref multimesh = multimesh_instance->get_multimesh(); if (multimesh.is_valid()) { Ref mesh = multimesh->get_mesh(); diff --git a/modules/navigation_geometry_parsers/geometry_parser_3d/multimeshinstance3d_navigation_geometry_parser_3d.h b/modules/navigation_geometry_parsers/geometry_parser_3d/multimeshinstance3d_navigation_geometry_parser_3d.h index 822710755..8ae97c352 100644 --- a/modules/navigation_geometry_parsers/geometry_parser_3d/multimeshinstance3d_navigation_geometry_parser_3d.h +++ b/modules/navigation_geometry_parsers/geometry_parser_3d/multimeshinstance3d_navigation_geometry_parser_3d.h @@ -35,9 +35,9 @@ class MultiMeshInstance3DNavigationGeometryParser3D : public NavigationGeometryParser3D { public: - virtual bool parses_node(Node *p_node) override; + virtual bool parses_node(Node *p_node); - virtual void parse_geometry(Node *p_node, Ref p_navigationmesh, Ref p_source_geometry) override; + virtual void parse_geometry(Node *p_node, Ref p_navigationmesh, Ref p_source_geometry); }; #endif // MULTIMESHINSTANCE3D_NAVIGATION_GEOMETRY_PARSER_3D_H diff --git a/modules/navigation_geometry_parsers/geometry_parser_3d/staticbody3d_navigation_geometry_parser_3d.cpp b/modules/navigation_geometry_parsers/geometry_parser_3d/staticbody3d_navigation_geometry_parser_3d.cpp index 796b16461..feb9ef290 100644 --- a/modules/navigation_geometry_parsers/geometry_parser_3d/staticbody3d_navigation_geometry_parser_3d.cpp +++ b/modules/navigation_geometry_parsers/geometry_parser_3d/staticbody3d_navigation_geometry_parser_3d.cpp @@ -31,54 +31,61 @@ #include "staticbody3d_navigation_geometry_parser_3d.h" #include "core/math/convex_hull.h" -#include "scene/3d/mesh_instance_3d.h" -#include "scene/3d/physics_body_3d.h" -#include "scene/resources/box_shape_3d.h" -#include "scene/resources/capsule_shape_3d.h" -#include "scene/resources/concave_polygon_shape_3d.h" -#include "scene/resources/convex_polygon_shape_3d.h" -#include "scene/resources/cylinder_shape_3d.h" -#include "scene/resources/height_map_shape_3d.h" +#include "scene/3d/mesh_instance.h" +#include "scene/3d/physics_body.h" +#include "scene/resources/box_shape.h" +#include "scene/resources/capsule_shape.h" +#include "scene/resources/concave_polygon_shape.h" +#include "scene/resources/convex_polygon_shape.h" +#include "scene/resources/cylinder_shape.h" +#include "scene/resources/height_map_shape.h" +#include "scene/resources/plane_shape.h" #include "scene/resources/primitive_meshes.h" -#include "scene/resources/shape_3d.h" -#include "scene/resources/sphere_shape_3d.h" -#include "scene/resources/world_boundary_shape_3d.h" +#include "scene/resources/shape.h" +#include "scene/resources/sphere_shape.h" + +#include "scene/resources/navigation_mesh.h" +#include "scene/resources/navigation_mesh_source_geometry_data_3d.h" bool StaticBody3DNavigationGeometryParser3D::parses_node(Node *p_node) { - return (Object::cast_to(p_node) != nullptr); + return (Object::cast_to(p_node) != nullptr); } void StaticBody3DNavigationGeometryParser3D::parse_geometry(Node *p_node, Ref p_navigationmesh, Ref p_source_geometry) { NavigationMesh::ParsedGeometryType parsed_geometry_type = p_navigationmesh->get_parsed_geometry_type(); uint32_t navigationmesh_collision_mask = p_navigationmesh->get_collision_mask(); - if (Object::cast_to(p_node) && parsed_geometry_type != NavigationMesh::PARSED_GEOMETRY_MESH_INSTANCES) { - StaticBody3D *static_body = Object::cast_to(p_node); + if (Object::cast_to(p_node) && parsed_geometry_type != NavigationMesh::PARSED_GEOMETRY_MESH_INSTANCES) { + StaticBody *static_body = Object::cast_to(p_node); if (static_body->get_collision_layer() & navigationmesh_collision_mask) { List shape_owners; static_body->get_shape_owners(&shape_owners); - for (uint32_t shape_owner : shape_owners) { + + for (List::Element *E = shape_owners.front(); E; E = E->next()) { + uint32_t shape_owner = E->get(); + if (static_body->is_shape_owner_disabled(shape_owner)) { continue; } + const int shape_count = static_body->shape_owner_get_shape_count(shape_owner); for (int shape_index = 0; shape_index < shape_count; shape_index++) { - Ref s = static_body->shape_owner_get_shape(shape_owner, shape_index); + Ref s = static_body->shape_owner_get_shape(shape_owner, shape_index); if (s.is_null()) { continue; } - const Transform3D transform = static_body->get_global_transform() * static_body->shape_owner_get_transform(shape_owner); + const Transform transform = static_body->get_global_transform() * static_body->shape_owner_get_transform(shape_owner); - BoxShape3D *box = Object::cast_to(*s); + BoxShape *box = Object::cast_to(*s); if (box) { Array arr; arr.resize(RS::ARRAY_MAX); - BoxMesh::create_mesh_array(arr, box->get_size()); + CubeMesh::create_mesh_array(arr, box->get_extents()); p_source_geometry->add_mesh_array(arr, transform); } - CapsuleShape3D *capsule = Object::cast_to(*s); + CapsuleShape *capsule = Object::cast_to(*s); if (capsule) { Array arr; arr.resize(RS::ARRAY_MAX); @@ -86,7 +93,7 @@ void StaticBody3DNavigationGeometryParser3D::parse_geometry(Node *p_node, Refadd_mesh_array(arr, transform); } - CylinderShape3D *cylinder = Object::cast_to(*s); + CylinderShape *cylinder = Object::cast_to(*s); if (cylinder) { Array arr; arr.resize(RS::ARRAY_MAX); @@ -94,7 +101,7 @@ void StaticBody3DNavigationGeometryParser3D::parse_geometry(Node *p_node, Refadd_mesh_array(arr, transform); } - SphereShape3D *sphere = Object::cast_to(*s); + SphereShape *sphere = Object::cast_to(*s); if (sphere) { Array arr; arr.resize(RS::ARRAY_MAX); @@ -102,23 +109,25 @@ void StaticBody3DNavigationGeometryParser3D::parse_geometry(Node *p_node, Refadd_mesh_array(arr, transform); } - ConcavePolygonShape3D *concave_polygon = Object::cast_to(*s); + ConcavePolygonShape *concave_polygon = Object::cast_to(*s); if (concave_polygon) { p_source_geometry->add_faces(concave_polygon->get_faces(), transform); } - ConvexPolygonShape3D *convex_polygon = Object::cast_to(*s); + ConvexPolygonShape *convex_polygon = Object::cast_to(*s); if (convex_polygon) { Vector varr = Variant(convex_polygon->get_points()); - Geometry3D::MeshData md; + Geometry::MeshData md; Error err = ConvexHullComputer::convex_hull(varr, md); if (err == OK) { - PackedVector3Array faces; + PoolVector3Array faces; - for (const Geometry3D::MeshData::Face &face : md.faces) { - for (uint32_t k = 2; k < face.indices.size(); ++k) { + for (int i = 0; i < md.faces.size(); ++i) { + const Geometry::MeshData::Face &face = md.faces[i]; + + for (int k = 2; k < face.indices.size(); ++k) { faces.push_back(md.vertices[face.indices[0]]); faces.push_back(md.vertices[face.indices[k - 1]]); faces.push_back(md.vertices[face.indices[k]]); @@ -129,18 +138,18 @@ void StaticBody3DNavigationGeometryParser3D::parse_geometry(Node *p_node, Ref(*s); + HeightMapShape *heightmap_shape = Object::cast_to(*s); if (heightmap_shape) { int heightmap_depth = heightmap_shape->get_map_depth(); int heightmap_width = heightmap_shape->get_map_width(); if (heightmap_depth >= 2 && heightmap_width >= 2) { - const Vector &map_data = heightmap_shape->get_map_data(); + const PoolVector &map_data = heightmap_shape->get_map_data(); Vector2 heightmap_gridsize(heightmap_width - 1, heightmap_depth - 1); Vector2 start = heightmap_gridsize * -0.5; - Vector vertex_array; + PoolVector vertex_array; vertex_array.resize((heightmap_depth - 1) * (heightmap_width - 1) * 6); int map_data_current_index = 0; diff --git a/modules/navigation_geometry_parsers/geometry_parser_3d/staticbody3d_navigation_geometry_parser_3d.h b/modules/navigation_geometry_parsers/geometry_parser_3d/staticbody3d_navigation_geometry_parser_3d.h index 1576cadbd..4c3e52495 100644 --- a/modules/navigation_geometry_parsers/geometry_parser_3d/staticbody3d_navigation_geometry_parser_3d.h +++ b/modules/navigation_geometry_parsers/geometry_parser_3d/staticbody3d_navigation_geometry_parser_3d.h @@ -35,9 +35,9 @@ class StaticBody3DNavigationGeometryParser3D : public NavigationGeometryParser3D { public: - virtual bool parses_node(Node *p_node) override; + virtual bool parses_node(Node *p_node) ; - virtual void parse_geometry(Node *p_node, Ref p_navigationmesh, Ref p_source_geometry) override; + virtual void parse_geometry(Node *p_node, Ref p_navigationmesh, Ref p_source_geometry) ; }; #endif // STATICBODY3D_NAVIGATION_GEOMETRY_PARSER_3D_H diff --git a/modules/navigation_geometry_parsers/register_types.cpp b/modules/navigation_geometry_parsers/register_types.cpp index c1902c1ef..3adb6874c 100644 --- a/modules/navigation_geometry_parsers/register_types.cpp +++ b/modules/navigation_geometry_parsers/register_types.cpp @@ -32,8 +32,31 @@ #include "core/config/engine.h" +#include "servers/navigation/navigation_mesh_generator.h" + +#include "geometry_parser_2d/meshinstance2d_navigation_geometry_parser_2d.h" +#include "geometry_parser_2d/multimeshinstance2d_navigation_geometry_parser_2d.h" +#include "geometry_parser_2d/polygon2d_navigation_geometry_parser_2d.h" +#include "geometry_parser_2d/staticbody2d_navigation_geometry_parser_2d.h" +#include "geometry_parser_2d/tilemap_navigation_geometry_parser_2d.h" +#ifndef _3D_DISABLED +#include "geometry_parser_3d/meshinstance3d_navigation_geometry_parser_3d.h" +#include "geometry_parser_3d/multimeshinstance3d_navigation_geometry_parser_3d.h" +#include "geometry_parser_3d/staticbody3d_navigation_geometry_parser_3d.h" +#endif // _3D_DISABLED + void register_navigation_geometry_parsers_types(ModuleRegistrationLevel p_level) { if (p_level == MODULE_REGISTRATION_LEVEL_SCENE) { + NavigationMeshGenerator::get_singleton()->register_geometry_parser_2d(memnew(MeshInstance2DNavigationGeometryParser2D)); + NavigationMeshGenerator::get_singleton()->register_geometry_parser_2d(memnew(MultiMeshInstance2DNavigationGeometryParser2D)); + NavigationMeshGenerator::get_singleton()->register_geometry_parser_2d(memnew(Polygon2DNavigationGeometryParser2D)); + NavigationMeshGenerator::get_singleton()->register_geometry_parser_2d(memnew(StaticBody2DNavigationGeometryParser2D)); + NavigationMeshGenerator::get_singleton()->register_geometry_parser_2d(memnew(TileMap2DNavigationGeometryParser2D)); +#ifndef _3D_DISABLED + NavigationMeshGenerator::get_singleton()->register_geometry_parser_3d(memnew(MeshInstance3DNavigationGeometryParser3D)); + NavigationMeshGenerator::get_singleton()->register_geometry_parser_3d(memnew(MultiMeshInstance3DNavigationGeometryParser3D)); + NavigationMeshGenerator::get_singleton()->register_geometry_parser_3d(memnew(StaticBody3DNavigationGeometryParser3D)); +#endif // _3D_DISABLED } } diff --git a/modules/navigation_mesh_generator/pandemonium_navigation_mesh_generator.cpp b/modules/navigation_mesh_generator/pandemonium_navigation_mesh_generator.cpp index b7c6c3f29..694838fd7 100644 --- a/modules/navigation_mesh_generator/pandemonium_navigation_mesh_generator.cpp +++ b/modules/navigation_mesh_generator/pandemonium_navigation_mesh_generator.cpp @@ -40,22 +40,8 @@ #include "scene/resources/navigation_mesh_source_geometry_data_2d.h" #include "scene/resources/navigation_mesh_source_geometry_data_3d.h" -/* -#include "servers/navigation/geometry_parser_2d/meshinstance2d_navigation_geometry_parser_2d.h" -#include "servers/navigation/geometry_parser_2d/multimeshinstance2d_navigation_geometry_parser_2d.h" -#include "servers/navigation/geometry_parser_2d/polygon2d_navigation_geometry_parser_2d.h" -#include "servers/navigation/geometry_parser_2d/staticbody2d_navigation_geometry_parser_2d.h" -#include "servers/navigation/geometry_parser_2d/tilemap_navigation_geometry_parser_2d.h" -*/ - #ifndef _3D_DISABLED #include "scene/3d/mesh_instance.h" - -/* -#include "servers/navigation/geometry_parser_3d/meshinstance3d_navigation_geometry_parser_3d.h" -#include "servers/navigation/geometry_parser_3d/multimeshinstance3d_navigation_geometry_parser_3d.h" -#include "servers/navigation/geometry_parser_3d/staticbody3d_navigation_geometry_parser_3d.h" -*/ #endif // _3D_DISABLED #ifdef CLIPPER_ENABLED