From 105d385e4b73f353350a3a1894eb0d9e933130c3 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 5 Jan 2021 22:27:49 +1100 Subject: Fix T84364: Sculpt symmetrize fails with shape keys Use the BMesh symmetrize operator instead of using the modifier code. While we could support shape-keys with the existing code used by the mirror modifier, we'd need to add code-paths for evaluated mesh & bmesh conversion to handle shape-keys differently just for this one case, since we want to avoid copying & processing shape-keys layers for evaluated meshes in general. --- source/blender/blenkernel/intern/mesh_mirror.c | 59 +++++++++++++++++++++----- 1 file changed, 48 insertions(+), 11 deletions(-) (limited to 'source/blender/blenkernel/intern/mesh_mirror.c') diff --git a/source/blender/blenkernel/intern/mesh_mirror.c b/source/blender/blenkernel/intern/mesh_mirror.c index 46764a56e60..a22b52d68d5 100644 --- a/source/blender/blenkernel/intern/mesh_mirror.c +++ b/source/blender/blenkernel/intern/mesh_mirror.c @@ -41,11 +41,11 @@ #include "MOD_modifiertypes.h" -Mesh *BKE_mesh_mirror_bisect_on_mirror_plane(MirrorModifierData *mmd, - const Mesh *mesh, - int axis, - const float plane_co[3], - float plane_no[3]) +Mesh *BKE_mesh_mirror_bisect_on_mirror_plane_for_modifier(MirrorModifierData *mmd, + const Mesh *mesh, + int axis, + const float plane_co[3], + float plane_no[3]) { bool do_bisect_flip_axis = ((axis == 0 && mmd->flag & MOD_MIR_BISECT_FLIP_AXIS_X) || (axis == 1 && mmd->flag & MOD_MIR_BISECT_FLIP_AXIS_Y) || @@ -97,11 +97,47 @@ Mesh *BKE_mesh_mirror_bisect_on_mirror_plane(MirrorModifierData *mmd, return result; } -Mesh *BKE_mesh_mirror_apply_mirror_on_axis(MirrorModifierData *mmd, - const ModifierEvalContext *UNUSED(ctx), - Object *ob, - const Mesh *mesh, - int axis) +void BKE_mesh_mirror_apply_mirror_on_axis(struct Main *bmain, + Mesh *mesh, + const int axis, + const float dist) +{ + BMesh *bm = BKE_mesh_to_bmesh_ex(mesh, + &(struct BMeshCreateParams){ + .use_toolflags = 1, + }, + &(struct BMeshFromMeshParams){ + .calc_face_normal = true, + .cd_mask_extra = + { + .vmask = CD_MASK_SHAPEKEY, + }, + }); + BMO_op_callf(bm, + (BMO_FLAG_DEFAULTS & ~BMO_FLAG_RESPECT_HIDE), + "symmetrize input=%avef direction=%i dist=%f use_shapekey=%b", + axis, + dist, + true); + + BM_mesh_bm_to_me(bmain, + bm, + mesh, + (&(struct BMeshToMeshParams){ + .calc_object_remap = true, + + })); + BM_mesh_free(bm); +} + +/** + * \warning This should _not_ be used to modify original meshes since + * it doesn't handle shape-keys, use #BKE_mesh_mirror_apply_mirror_on_axis instead. + */ +Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd, + Object *ob, + const Mesh *mesh, + const int axis) { const float tolerance_sq = mmd->tolerance * mmd->tolerance; const bool do_vtargetmap = (mmd->flag & MOD_MIR_NO_MERGE) == 0; @@ -157,7 +193,8 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis(MirrorModifierData *mmd, Mesh *mesh_bisect = NULL; if (do_bisect) { - mesh_bisect = BKE_mesh_mirror_bisect_on_mirror_plane(mmd, mesh, axis, plane_co, plane_no); + mesh_bisect = BKE_mesh_mirror_bisect_on_mirror_plane_for_modifier( + mmd, mesh, axis, plane_co, plane_no); mesh = mesh_bisect; } -- cgit v1.2.3