Browse Source

Let MultiMeshInstances affect NavigationMeshes

Carlo Cabanilla 3 years ago
parent
commit
75b61ea1f4
1 changed files with 16 additions and 0 deletions
  1. 16 0
      modules/navigation/navigation_mesh_generator.cpp

+ 16 - 0
modules/navigation/navigation_mesh_generator.cpp

@@ -36,6 +36,7 @@
 #include "core/os/thread.h"
 #include "scene/3d/collision_shape_3d.h"
 #include "scene/3d/mesh_instance_3d.h"
+#include "scene/3d/multimesh_instance_3d.h"
 #include "scene/3d/physics_body_3d.h"
 #include "scene/resources/box_shape_3d.h"
 #include "scene/resources/capsule_shape_3d.h"
@@ -148,6 +149,21 @@ void NavigationMeshGenerator::_parse_geometry(Transform3D p_accumulated_transfor
 		}
 	}
 
+	if (Object::cast_to<MultiMeshInstance3D>(p_node) && p_generate_from != NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS) {
+		MultiMeshInstance3D *multimesh_instance = Object::cast_to<MultiMeshInstance3D>(p_node);
+		Ref<MultiMesh> multimesh = multimesh_instance->get_multimesh();
+		Ref<Mesh> mesh = multimesh->get_mesh();
+		if (mesh.is_valid()) {
+			int n = multimesh->get_visible_instance_count();
+			if (n == -1) {
+				n = multimesh->get_instance_count();
+			}
+			for (int i = 0; i < n; i++) {
+				_add_mesh(mesh, p_accumulated_transform * multimesh->get_instance_transform(i), p_verticies, p_indices);
+			}
+		}
+	}
+
 #ifdef MODULE_CSG_ENABLED
 	if (Object::cast_to<CSGShape3D>(p_node) && p_generate_from != NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS) {
 		CSGShape3D *csg_shape = Object::cast_to<CSGShape3D>(p_node);