Cleanup: Remove unnecessary/wrong solidify modifier normal recalculation

This modified the original normals cache, which is a more obvious error
now that the cache is shared between meshes. The goal of the code was
to reduce unnecessary calculation of normals in the result, but this is
not necessarily faster, and not worth the complexity, especially in an
already very complex area.
This commit is contained in:
Hans Goudey
2023-08-31 14:15:28 -04:00
parent d600a38e44
commit 74bd927f7c
@@ -977,18 +977,6 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
MEM_freeN(vert_nors);
}
/* must recalculate normals with vgroups since they can displace unevenly #26888. */
if (BKE_mesh_vert_normals_are_dirty(mesh) || do_rim || dvert) {
/* Pass. */
}
else if (do_shell) {
uint i;
/* flip vertex normals for copied verts */
for (i = 0; i < verts_num; i++) {
negate_v3((float *)&vert_normals[i].x);
}
}
/* Add vertex weights for rim and shell vgroups. */
if (shell_defgrp_index != -1 || rim_defgrp_index != -1) {
MDeformVert *dst_dvert = BKE_mesh_deform_verts_for_write(result);
@@ -1015,26 +1003,6 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
if (do_rim) {
uint i;
/* NOTE(@ideasman42): Unfortunately re-calculate the normals for the new edge
* faces is necessary. This could be done in many ways, but probably the quickest
* way is to calculate the average normals for side faces only.
* Then blend them with the normals of the edge verts.
*
* At the moment its easiest to allocate an entire array for every vertex,
* even though we only need edge verts. */
#define SOLIDIFY_SIDE_NORMALS
#ifdef SOLIDIFY_SIDE_NORMALS
/* NOTE(@sybren): due to the code setting normals dirty a few lines above,
* do_side_normals is always false. */
const bool do_side_normals = !BKE_mesh_vert_normals_are_dirty(result);
/* annoying to allocate these since we only need the edge verts, */
float(*edge_vert_nos)[3] = do_side_normals ? static_cast<float(*)[3]>(MEM_calloc_arrayN(
verts_num, sizeof(float[3]), __func__)) :
nullptr;
float nor[3];
#endif
const float crease_rim = smd->crease_rim;
const float crease_outer = smd->crease_outer;
const float crease_inner = smd->crease_inner;
@@ -1163,46 +1131,9 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
*cr = tcr > 1.0f ? 1.0f : tcr;
}
#ifdef SOLIDIFY_SIDE_NORMALS
if (do_side_normals) {
normal_quad_v3(nor,
vert_positions[new_corner_verts[j - 4]],
vert_positions[new_corner_verts[j - 3]],
vert_positions[new_corner_verts[j - 2]],
vert_positions[new_corner_verts[j - 1]]);
add_v3_v3(edge_vert_nos[edge[0]], nor);
add_v3_v3(edge_vert_nos[edge[1]], nor);
}
#endif
new_face_index++;
}
#ifdef SOLIDIFY_SIDE_NORMALS
if (do_side_normals) {
for (i = 0; i < rimVerts; i++) {
const blender::int2 &edge_orig = edges[i];
const blender::int2 &edge = edges[edges_num * stride + i];
float nor_cpy[3];
int k;
/* NOTE: only the first vertex (lower half of the index) is calculated. */
BLI_assert(edge[0] < verts_num);
normalize_v3_v3(nor_cpy, edge_vert_nos[edge_orig[0]]);
for (k = 0; k < 2; k++) { /* loop over both verts of the edge */
copy_v3_v3(nor, vert_normals[*(&edge[0] + k)]);
add_v3_v3(nor, nor_cpy);
normalize_v3(nor);
copy_v3_v3((float *)&vert_normals[*(&edge[0] + k)].x, nor);
}
}
MEM_freeN(edge_vert_nos);
}
#endif
MEM_freeN(new_vert_arr);
MEM_freeN(new_edge_arr);
@@ -1217,6 +1148,4 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
return result;
}
#undef SOLIDIFY_SIDE_NORMALS
/** \} */