2
0
Эх сурвалжийг харах

Merge pull request #88198 from lawnjelly/fix_facecount_bug

[3.x] Fix `Mesh::get_face_count()`
Rémi Verschelde 1 жил өмнө
parent
commit
1ad9e856a0

+ 1 - 1
editor/plugins/merge_group_editor_plugin.cpp

@@ -324,7 +324,7 @@ void MergeGroupEditorPlugin::_remove_queue_deleted_nodes_recursive(Node *p_node)
 uint32_t MergeGroupEditorPlugin::_get_mesh_poly_count(const MeshInstance &p_mi) const {
 	Ref<Mesh> rmesh = p_mi.get_mesh();
 	if (rmesh.is_valid()) {
-		return rmesh->get_face_count();
+		return rmesh->get_triangle_count();
 	}
 
 	return 0;

+ 10 - 10
scene/resources/mesh.cpp

@@ -42,7 +42,7 @@
 
 Mesh::ConvexDecompositionFunc Mesh::convex_decomposition_function = nullptr;
 
-int Mesh::surface_get_face_count(int p_idx) const {
+int Mesh::surface_get_triangle_count(int p_idx) const {
 	ERR_FAIL_INDEX_V(p_idx, get_surface_count(), 0);
 
 	switch (surface_get_primitive_type(p_idx)) {
@@ -50,14 +50,14 @@ int Mesh::surface_get_face_count(int p_idx) const {
 			int len = (surface_get_format(p_idx) & ARRAY_FORMAT_INDEX) ? surface_get_array_index_len(p_idx) : surface_get_array_len(p_idx);
 			// Don't error if zero, it's valid (we'll just skip it later).
 			ERR_FAIL_COND_V_MSG((len % 3) != 0, 0, vformat("Ignoring surface %d, incorrect %s count: %d (for PRIMITIVE_TRIANGLES).", p_idx, (surface_get_format(p_idx) & ARRAY_FORMAT_INDEX) ? "index" : "vertex", len));
-			return len;
+			return len / 3;
 		} break;
 		case PRIMITIVE_TRIANGLE_FAN:
 		case PRIMITIVE_TRIANGLE_STRIP: {
 			int len = (surface_get_format(p_idx) & ARRAY_FORMAT_INDEX) ? surface_get_array_index_len(p_idx) : surface_get_array_len(p_idx);
 			// Don't error if zero, it's valid (we'll just skip it later).
 			ERR_FAIL_COND_V_MSG(len != 0 && len < 3, 0, vformat("Ignoring surface %d, incorrect %s count: %d (for %s).", p_idx, (surface_get_format(p_idx) & ARRAY_FORMAT_INDEX) ? "index" : "vertex", len, (surface_get_primitive_type(p_idx) == PRIMITIVE_TRIANGLE_FAN) ? "PRIMITIVE_TRIANGLE_FAN" : "PRIMITIVE_TRIANGLE_STRIP"));
-			return (len == 0) ? 0 : (len - 2) * 3;
+			return (len == 0) ? 0 : (len - 2);
 		} break;
 		default: {
 		} break;
@@ -66,14 +66,14 @@ int Mesh::surface_get_face_count(int p_idx) const {
 	return 0;
 }
 
-int Mesh::get_face_count() const {
-	int faces_size = 0;
+int Mesh::get_triangle_count() const {
+	int triangle_count = 0;
 
 	for (int i = 0; i < get_surface_count(); i++) {
-		faces_size += surface_get_face_count(i);
+		triangle_count += surface_get_triangle_count(i);
 	}
 
-	return faces_size;
+	return triangle_count;
 }
 
 Ref<TriangleMesh> Mesh::generate_triangle_mesh_from_aabb() const {
@@ -151,14 +151,14 @@ Ref<TriangleMesh> Mesh::generate_triangle_mesh() const {
 		return triangle_mesh;
 	}
 
-	int faces_size = get_face_count();
+	int faces_vertex_count = get_triangle_count() * 3;
 
-	if (faces_size == 0) {
+	if (faces_vertex_count == 0) {
 		return triangle_mesh;
 	}
 
 	PoolVector<Vector3> faces;
-	faces.resize(faces_size);
+	faces.resize(faces_vertex_count);
 	PoolVector<Vector3>::Write facesw = faces.write();
 
 	int widx = 0;

+ 2 - 2
scene/resources/mesh.h

@@ -137,11 +137,11 @@ public:
 	virtual void surface_set_material(int p_idx, const Ref<Material> &p_material) = 0;
 	virtual Ref<Material> surface_get_material(int p_idx) const = 0;
 	virtual int get_blend_shape_count() const = 0;
-	int surface_get_face_count(int p_idx) const;
+	int surface_get_triangle_count(int p_idx) const;
 	virtual StringName get_blend_shape_name(int p_index) const = 0;
 	virtual void set_blend_shape_name(int p_index, const StringName &p_name) = 0;
 
-	int get_face_count() const;
+	int get_triangle_count() const;
 	PoolVector<Face3> get_faces() const;
 	Ref<TriangleMesh> generate_triangle_mesh() const;
 	Ref<TriangleMesh> generate_triangle_mesh_from_aabb() const;