diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-01-05 14:27:49 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-01-05 14:48:12 +0300 |
commit | 105d385e4b73f353350a3a1894eb0d9e933130c3 (patch) | |
tree | 601a0689e7caeeae235a45dc9f06266ab5a5176a /source/blender/blenkernel | |
parent | 724110487721226812a111cb147b85622f2c19e4 (diff) |
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.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_mesh_mirror.h | 31 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh_mirror.c | 59 |
2 files changed, 65 insertions, 25 deletions
diff --git a/source/blender/blenkernel/BKE_mesh_mirror.h b/source/blender/blenkernel/BKE_mesh_mirror.h index 2c6920a18bf..a91f0787e68 100644 --- a/source/blender/blenkernel/BKE_mesh_mirror.h +++ b/source/blender/blenkernel/BKE_mesh_mirror.h @@ -23,27 +23,30 @@ * \ingroup bke */ -#include "BLI_utildefines.h" - #ifdef __cplusplus extern "C" { #endif +struct Main; +struct Mesh; struct MirrorModifierData; -struct ModifierEvalContext; struct Object; -struct Mesh *BKE_mesh_mirror_bisect_on_mirror_plane(struct MirrorModifierData *mmd, - const struct Mesh *mesh, - int axis, - const float plane_co[3], - float plane_no[3]); - -struct Mesh *BKE_mesh_mirror_apply_mirror_on_axis(struct MirrorModifierData *mmd, - const struct ModifierEvalContext *UNUSED(ctx), - struct Object *ob, - const struct Mesh *mesh, - int axis); +struct Mesh *BKE_mesh_mirror_bisect_on_mirror_plane_for_modifier(struct MirrorModifierData *mmd, + const struct Mesh *mesh, + int axis, + const float plane_co[3], + float plane_no[3]); + +void BKE_mesh_mirror_apply_mirror_on_axis(struct Main *bmain, + struct Mesh *mesh, + 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, + int axis); #ifdef __cplusplus } 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; } |