Merge pull request #29749 from JFonS/add_csg_navmesh

Take CSG into account for nav-mesh generation
This commit is contained in:
Rémi Verschelde 2019-06-13 17:45:34 +02:00 committed by GitHub
commit b2b06dd4a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -116,9 +116,9 @@ protected:
virtual void _validate_property(PropertyInfo &property) const; virtual void _validate_property(PropertyInfo &property) const;
public:
Array get_meshes() const; Array get_meshes() const;
public:
void set_operation(Operation p_operation); void set_operation(Operation p_operation);
Operation get_operation() const; Operation get_operation() const;

View File

@ -45,6 +45,10 @@
#include "scene/resources/shape.h" #include "scene/resources/shape.h"
#include "scene/resources/sphere_shape.h" #include "scene/resources/sphere_shape.h"
#ifdef MODULE_CSG_ENABLED
#include "modules/csg/csg_shape.h"
#endif
EditorNavigationMeshGenerator *EditorNavigationMeshGenerator::singleton = NULL; EditorNavigationMeshGenerator *EditorNavigationMeshGenerator::singleton = NULL;
void EditorNavigationMeshGenerator::_add_vertex(const Vector3 &p_vec3, Vector<float> &p_verticies) { void EditorNavigationMeshGenerator::_add_vertex(const Vector3 &p_vec3, Vector<float> &p_verticies) {
@ -134,6 +138,20 @@ void EditorNavigationMeshGenerator::_parse_geometry(Transform p_accumulated_tran
} }
} }
#ifdef MODULE_CSG_ENABLED
if (Object::cast_to<CSGShape>(p_node) && p_generate_from != NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS) {
CSGShape *csg_shape = Object::cast_to<CSGShape>(p_node);
Array meshes = csg_shape->get_meshes();
if (!meshes.empty()) {
Ref<Mesh> 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<StaticBody>(p_node) && p_generate_from != NavigationMesh::PARSED_GEOMETRY_MESH_INSTANCES) { if (Object::cast_to<StaticBody>(p_node) && p_generate_from != NavigationMesh::PARSED_GEOMETRY_MESH_INSTANCES) {
StaticBody *static_body = Object::cast_to<StaticBody>(p_node); StaticBody *static_body = Object::cast_to<StaticBody>(p_node);