소스 검색

Merge pull request #107507 from smix8/csg_mesh_opti

Create more optimized CSGShape3D baked static mesh
Rémi Verschelde 1 개월 전
부모
커밋
2a71b21b4e
1개의 변경된 파일14개의 추가작업 그리고 1개의 파일을 삭제
  1. 14 1
      modules/csg/csg_shape.cpp

+ 14 - 1
modules/csg/csg_shape.cpp

@@ -36,6 +36,7 @@
 #include "core/math/geometry_2d.h"
 #include "scene/resources/3d/navigation_mesh_source_geometry_data_3d.h"
 #include "scene/resources/navigation_mesh.h"
+#include "scene/resources/surface_tool.h"
 #ifndef NAVIGATION_3D_DISABLED
 #include "servers/navigation_server_3d.h"
 #endif // NAVIGATION_3D_DISABLED
@@ -736,7 +737,19 @@ void CSGShape3D::update_shape() {
 Ref<ArrayMesh> CSGShape3D::bake_static_mesh() {
 	Ref<ArrayMesh> baked_mesh;
 	if (is_root_shape() && root_mesh.is_valid()) {
-		baked_mesh = root_mesh;
+		Ref<SurfaceTool> st;
+		st.instantiate();
+
+		int surface_count = root_mesh->get_surface_count();
+		for (int i = 0; i < surface_count; i++) {
+			st->append_from(root_mesh, i, Transform3D());
+		}
+		st->generate_normals();
+		st->generate_tangents();
+		st->index();
+		st->optimize_indices_for_cache();
+
+		baked_mesh = st->commit();
 	}
 	return baked_mesh;
 }