diff options
author | Bastien Montagne <mont29> | 2021-11-12 10:07:07 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2021-11-25 12:21:49 +0300 |
commit | a0acb9bd0cc049b7b8b941b251c42684b4a0f274 (patch) | |
tree | b9e9b798f744ca6186fcc2388056d4d9267e9db0 /source/blender/blenkernel | |
parent | e6cd4761e7c3043c8e9dc789b6eb6d0aa1b723bd (diff) |
Fix T91444: Edge Loop Preview fails with two Mirror Modifiers
The mirror modifiers merge option caused unnecessary re-ordering
to the vertex array with original vertices merging into their copies.
While this wasn't an error, it meant creating a 1:1 mapping from input
vertices to their final output wasn't reliable (when looping over
vertices first to last) as is done in
BKE_editmesh_vert_coords_when_deformed.
As merging in either direction is supported, keep the source meshes
vertices in-order since it allows the vertex coordinates to be extracted.
NOTE: Since this change introduce issues for some cases (e.g. bound
modifiers like SurfaceDeform), this change is only applied to newly
created modifiers, existing ones will still use the old incorrect merge
behavior.
Reviewed By: @brecht
Maniphest Tasks: T93321, T91444
Differential Revision: https://developer.blender.org/D13355
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_mesh_mirror.h | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh_mirror.c | 57 |
2 files changed, 50 insertions, 17 deletions
diff --git a/source/blender/blenkernel/BKE_mesh_mirror.h b/source/blender/blenkernel/BKE_mesh_mirror.h index 7b230b04410..eaa479be867 100644 --- a/source/blender/blenkernel/BKE_mesh_mirror.h +++ b/source/blender/blenkernel/BKE_mesh_mirror.h @@ -43,10 +43,12 @@ void BKE_mesh_mirror_apply_mirror_on_axis(struct Main *bmain, const int axis, const float dist); -struct Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(struct MirrorModifierData *mmd, - struct Object *ob, - const struct Mesh *mesh, - const int axis); +struct Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier( + struct MirrorModifierData *mmd, + struct Object *ob, + const struct Mesh *mesh, + const int axis, + const bool use_correct_order_on_merge); #ifdef __cplusplus } diff --git a/source/blender/blenkernel/intern/mesh_mirror.c b/source/blender/blenkernel/intern/mesh_mirror.c index b20d81e7b9c..2756629b440 100644 --- a/source/blender/blenkernel/intern/mesh_mirror.c +++ b/source/blender/blenkernel/intern/mesh_mirror.c @@ -137,7 +137,8 @@ void BKE_mesh_mirror_apply_mirror_on_axis(struct Main *bmain, Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd, Object *ob, const Mesh *mesh, - const int axis) + const int axis, + const bool use_correct_order_on_merge) { const float tolerance_sq = mmd->tolerance * mmd->tolerance; const bool do_vtargetmap = (mmd->flag & MOD_MIR_NO_MERGE) == 0; @@ -260,21 +261,51 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd, mul_m4_v3(mtx, mv->co); if (do_vtargetmap) { - /* compare location of the original and mirrored vertex, to see if they - * should be mapped for merging */ - if (UNLIKELY(len_squared_v3v3(mv_prev->co, mv->co) < tolerance_sq)) { - *vtmap_a = maxVerts + i; - tot_vtargetmap++; - - /* average location */ - mid_v3_v3v3(mv->co, mv_prev->co, mv->co); - copy_v3_v3(mv_prev->co, mv->co); - } - else { + /* Compare location of the original and mirrored vertex, + * to see if they should be mapped for merging. + * + * Always merge from the copied into the original vertices so it's possible to + * generate a 1:1 mapping by scanning vertices from the beginning of the array + * as is done in #BKE_editmesh_vert_coords_when_deformed. Without this, + * the coordinates returned will sometimes point to the copied vertex locations, see: + * T91444. + * + * However, such a change also affects non-versionable things like some modifiers binding, so + * we cannot enforce that behavior on existing modifiers, in which case we keep using the + * old, incorrect behavior of merging the source vertex into its copy. + */ + if (use_correct_order_on_merge) { + if (UNLIKELY(len_squared_v3v3(mv_prev->co, mv->co) < tolerance_sq)) { + *vtmap_b = i; + tot_vtargetmap++; + + /* average location */ + mid_v3_v3v3(mv->co, mv_prev->co, mv->co); + copy_v3_v3(mv_prev->co, mv->co); + } + else { + *vtmap_b = -1; + } + + /* Fill here to avoid 2x loops. */ *vtmap_a = -1; } + else { + if (UNLIKELY(len_squared_v3v3(mv_prev->co, mv->co) < tolerance_sq)) { + *vtmap_a = maxVerts + i; + tot_vtargetmap++; + + /* average location */ + mid_v3_v3v3(mv->co, mv_prev->co, mv->co); + copy_v3_v3(mv_prev->co, mv->co); + } + else { + *vtmap_a = -1; + } - *vtmap_b = -1; /* fill here to avoid 2x loops */ + /* Fill here to avoid 2x loops. */ + *vtmap_b = -1; + } vtmap_a++; vtmap_b++; |