From 5a8003091ca62f87f44ac05232e36a8934818d13 Mon Sep 17 00:00:00 2001 From: Philipp Oeser Date: Thu, 20 Jun 2024 15:41:23 +0200 Subject: [PATCH] Fix #123181: Sculpt Transform tools dont keep verts on the symmetry axis From the user perspective, the transform tools in editmode and sculptmode look like the same tools, the equal behavior could be expected. So now set vertices on the mirror axis (check with the same epsilon as editmode transform) while transforming, replicating what `mesh_transdata_mirror_apply` does. Pull Request: https://projects.blender.org/blender/blender/pulls/123428 --- .../editors/sculpt_paint/sculpt_transform.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source/blender/editors/sculpt_paint/sculpt_transform.cc b/source/blender/editors/sculpt_paint/sculpt_transform.cc index 540a5321131..f9b1f25b8e1 100644 --- a/source/blender/editors/sculpt_paint/sculpt_transform.cc +++ b/source/blender/editors/sculpt_paint/sculpt_transform.cc @@ -138,6 +138,8 @@ static std::array transform_matrices_init( return mats; } +static constexpr float transform_mirror_max_distance_eps = 0.00002f; + static void transform_node(Object &ob, const std::array &transform_mats, PBVHNode *node) @@ -149,6 +151,8 @@ static void transform_node(Object &ob, PBVHVertexIter vd; + const ePaintSymmetryFlags symm = SCULPT_mesh_symmetry_xyz_get(ob); + undo::push_node(ob, node, undo::Type::Position); BKE_pbvh_vertex_iter_begin (*ss.pbvh, node, vd, PBVH_ITER_UNIQUE) { SCULPT_orig_vert_data_update(orig_data, vd); @@ -172,6 +176,17 @@ static void transform_node(Object &ob, sub_v3_v3v3(disp, transformed_co, start_co); mul_v3_fl(disp, 1.0f - fade); add_v3_v3v3(vd.co, start_co, disp); + + /* Keep vertices on the mirror axis. */ + if ((symm & PAINT_SYMM_X) && (fabs(start_co[0]) < transform_mirror_max_distance_eps)) { + vd.co[0] = 0.0f; + } + if ((symm & PAINT_SYMM_Y) && (fabs(start_co[1]) < transform_mirror_max_distance_eps)) { + vd.co[1] = 0.0f; + } + if ((symm & PAINT_SYMM_Z) && (fabs(start_co[2]) < transform_mirror_max_distance_eps)) { + vd.co[2] = 0.0f; + } } BKE_pbvh_vertex_iter_end;