From 2b8215a196d2be994b58323eb10870f4900bf618 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Thu, 2 Nov 2023 14:17:41 -0700 Subject: [PATCH] Fix dramatically overallocated normal weights The weight is per-attribute scalar (X, Y, Z), not per-vertex; this was the case even before the library update so this appears to be an oversight. --- scene/resources/importer_mesh.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/scene/resources/importer_mesh.cpp b/scene/resources/importer_mesh.cpp index 36baec919a8..f3291aaa76b 100644 --- a/scene/resources/importer_mesh.cpp +++ b/scene/resources/importer_mesh.cpp @@ -418,11 +418,10 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, float p_normal_spli } } - LocalVector normal_weights; - normal_weights.resize(merged_vertex_count); - for (unsigned int j = 0; j < merged_vertex_count; j++) { - normal_weights[j] = 2.0; // Give some weight to normal preservation, may be worth exposing as an import setting - } + const float normal_weights[3] = { + // Give some weight to normal preservation, may be worth exposing as an import setting + 2.0f, 2.0f, 2.0f + }; Vector merged_vertices_f32 = vector3_to_float32_array(merged_vertices_ptr, merged_vertex_count); float scale = SurfaceTool::simplify_scale_func(merged_vertices_f32.ptr(), merged_vertex_count, sizeof(float) * 3); @@ -462,7 +461,7 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, float p_normal_spli sizeof(float) * 3, // Vertex stride merged_normals_f32.ptr(), sizeof(float) * 3, // Attribute stride - normal_weights.ptr(), 3, + normal_weights, 3, index_target, max_mesh_error, simplify_options,