From a50758b8f6302f3450a01031aad22f986b25e11f Mon Sep 17 00:00:00 2001 From: trollodel <33117082+trollodel@users.noreply.github.com> Date: Sun, 1 May 2022 13:30:58 +0200 Subject: [PATCH] Use CollisionObject3D API when baking the navmesh with static colliders, instead of collecting CollisionShape3D nodes (cherry picked from commit 72c37c4bcd50e34b81c3dc5a2c5b8112014cc525) --- .../navigation/navigation_mesh_generator.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/modules/navigation/navigation_mesh_generator.cpp b/modules/navigation/navigation_mesh_generator.cpp index 0932bc758..9cc737cad 100644 --- a/modules/navigation/navigation_mesh_generator.cpp +++ b/modules/navigation/navigation_mesh_generator.cpp @@ -35,7 +35,6 @@ //#include "core/math/quick_hull.h" //#include "core/math/convex_hull.h" #include "core/os/thread.h" -#include "scene/3d/collision_shape.h" #include "scene/3d/mesh_instance.h" #include "scene/3d/multimesh_instance.h" #include "scene/3d/physics_body.h" @@ -187,14 +186,18 @@ void NavigationMeshGenerator::_parse_geometry(const Transform &p_navmesh_xform, StaticBody *static_body = Object::cast_to(p_node); if (static_body->get_collision_layer() & p_collision_mask) { - for (int i = 0; i < p_node->get_child_count(); ++i) { - Node *child = p_node->get_child(i); - if (Object::cast_to(child)) { - CollisionShape *col_shape = Object::cast_to(child); + List shape_owners; + static_body->get_shape_owners(&shape_owners); + for (List::Element *E = shape_owners.front(); E; E = E->next()) { + uint32_t shape_owner = E->get(); + const int shape_count = static_body->shape_owner_get_shape_count(shape_owner); + for (int i = 0; i < shape_count; i++) { + Ref s = static_body->shape_owner_get_shape(shape_owner, i); + if (s.is_null()) { + continue; + } - Transform transform = p_navmesh_xform * static_body->get_global_transform() * col_shape->get_transform(); - - Ref s = col_shape->get_shape(); + const Transform transform = p_navmesh_xform * static_body->get_global_transform() * static_body->shape_owner_get_transform(shape_owner); BoxShape *box = Object::cast_to(*s); if (box) {