From 051ef5ead297a577a54b49f2f964144ff8841214 Mon Sep 17 00:00:00 2001 From: jfons Date: Thu, 13 Jun 2019 13:29:43 +0200 Subject: [PATCH] Take CSG into account for nav-mesh generation --- modules/csg/csg_shape.h | 2 +- modules/recast/navigation_mesh_generator.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/csg/csg_shape.h b/modules/csg/csg_shape.h index a5b2238e6b0..2171f27f96b 100644 --- a/modules/csg/csg_shape.h +++ b/modules/csg/csg_shape.h @@ -116,9 +116,9 @@ protected: virtual void _validate_property(PropertyInfo &property) const; +public: Array get_meshes() const; -public: void set_operation(Operation p_operation); Operation get_operation() const; diff --git a/modules/recast/navigation_mesh_generator.cpp b/modules/recast/navigation_mesh_generator.cpp index 0cac07e3e72..14467dc5c77 100644 --- a/modules/recast/navigation_mesh_generator.cpp +++ b/modules/recast/navigation_mesh_generator.cpp @@ -45,6 +45,10 @@ #include "scene/resources/shape.h" #include "scene/resources/sphere_shape.h" +#ifdef MODULE_CSG_ENABLED +#include "modules/csg/csg_shape.h" +#endif + EditorNavigationMeshGenerator *EditorNavigationMeshGenerator::singleton = NULL; void EditorNavigationMeshGenerator::_add_vertex(const Vector3 &p_vec3, Vector &p_verticies) { @@ -134,6 +138,20 @@ void EditorNavigationMeshGenerator::_parse_geometry(Transform p_accumulated_tran } } +#ifdef MODULE_CSG_ENABLED + if (Object::cast_to(p_node) && p_generate_from != NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS) { + + CSGShape *csg_shape = Object::cast_to(p_node); + Array meshes = csg_shape->get_meshes(); + if (!meshes.empty()) { + Ref mesh = meshes[1]; + if (mesh.is_valid()) { + _add_mesh(mesh, p_accumulated_transform * csg_shape->get_transform(), p_verticies, p_indices); + } + } + } +#endif + if (Object::cast_to(p_node) && p_generate_from != NavigationMesh::PARSED_GEOMETRY_MESH_INSTANCES) { StaticBody *static_body = Object::cast_to(p_node);