From 5502517c3c12086c111ae5477fae9c0d2eb8a84c Mon Sep 17 00:00:00 2001 From: Pablo Dobarro Date: Fri, 18 Sep 2020 19:58:48 +0200 Subject: Unify all XYZ symmetry options using Mesh Symmetry This adds XYZ symmetry as a property of meshes and updates all modes to use the mesh symmetry by default to have a consistent tool behavior between all modes and when switching objects. Reviewed By: brecht, mano-wii, campbellbarton Maniphest Tasks: T79785 Differential Revision: https://developer.blender.org/D8587 --- source/blender/editors/sculpt_paint/paint_cursor.c | 2 +- source/blender/editors/sculpt_paint/paint_image_proj.c | 3 ++- source/blender/editors/sculpt_paint/paint_mask.c | 4 +--- source/blender/editors/sculpt_paint/paint_vertex.c | 13 +++++++------ .../editors/sculpt_paint/paint_vertex_weight_ops.c | 15 ++++++++++----- .../editors/sculpt_paint/paint_vertex_weight_utils.c | 2 +- source/blender/editors/sculpt_paint/sculpt.c | 12 +++++++++--- source/blender/editors/sculpt_paint/sculpt_automasking.c | 2 +- source/blender/editors/sculpt_paint/sculpt_boundary.c | 10 +++++----- source/blender/editors/sculpt_paint/sculpt_intern.h | 3 +++ source/blender/editors/sculpt_paint/sculpt_mask_expand.c | 2 +- source/blender/editors/sculpt_paint/sculpt_pose.c | 8 ++++---- source/blender/editors/sculpt_paint/sculpt_transform.c | 5 ++--- 13 files changed, 47 insertions(+), 34 deletions(-) (limited to 'source/blender/editors/sculpt_paint') diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c index 55abb269660..69b2a7d1fbb 100644 --- a/source/blender/editors/sculpt_paint/paint_cursor.c +++ b/source/blender/editors/sculpt_paint/paint_cursor.c @@ -1090,7 +1090,7 @@ static void cursor_draw_point_with_symmetry(const uint gpuattr, Object *ob, const float radius) { - const char symm = sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL; + const char symm = SCULPT_mesh_symmetry_xyz_get(ob); float location[3], symm_rot_mat[4][4]; for (int i = 0; i <= symm; i++) { diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index b0ad3ae1302..6f115acc856 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -5887,7 +5887,8 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int m ps_handle->orig_brush_size = BKE_brush_size_get(scene, ps_handle->brush); - ps_handle->symmetry_flags = settings->imapaint.paint.symmetry_flags & PAINT_SYMM_AXIS_ALL; + Mesh *mesh = BKE_mesh_from_object(ob); + ps_handle->symmetry_flags = mesh->symmetry; ps_handle->ps_views_tot = 1 + (pow_i(2, count_bits_i(ps_handle->symmetry_flags)) - 1); bool is_multi_view = (ps_handle->ps_views_tot != 1); diff --git a/source/blender/editors/sculpt_paint/paint_mask.c b/source/blender/editors/sculpt_paint/paint_mask.c index 1f86fc84f59..fc17af8d2cb 100644 --- a/source/blender/editors/sculpt_paint/paint_mask.c +++ b/source/blender/editors/sculpt_paint/paint_mask.c @@ -312,8 +312,6 @@ static void sculpt_gesture_context_init_common(bContext *C, { Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ED_view3d_viewcontext_init(C, &sgcontext->vc, depsgraph); - - Sculpt *sd = sgcontext->vc.scene->toolsettings->sculpt; Object *ob = sgcontext->vc.obact; /* Operator properties. */ @@ -323,7 +321,7 @@ static void sculpt_gesture_context_init_common(bContext *C, sgcontext->ss = ob->sculpt; /* Symmetry. */ - sgcontext->symm = sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL; + sgcontext->symm = SCULPT_mesh_symmetry_xyz_get(ob); /* View Normal. */ float mat[3][3]; diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 3753709875b..4a3babde5f3 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -765,7 +765,7 @@ static void do_weight_paint_vertex_single( MDeformWeight *dw_mirr; /* from now on we can check if mirrors enabled if this var is -1 and not bother with the flag */ - if (me->editflag & ME_EDIT_MIRROR_X) { + if (me->editflag & ME_EDIT_VERTEX_GROUPS_X_SYMMETRY) { index_mirr = mesh_get_x_mirror_vert(ob, NULL, index, topology); vgroup_mirr = wpi->mirror.index; @@ -961,7 +961,7 @@ static void do_weight_paint_vertex_multi( float dw_rel_free, dw_rel_locked; /* from now on we can check if mirrors enabled if this var is -1 and not bother with the flag */ - if (me->editflag & ME_EDIT_MIRROR_X) { + if (me->editflag & ME_EDIT_VERTEX_GROUPS_X_SYMMETRY) { index_mirr = mesh_get_x_mirror_vert(ob, NULL, index, topology); if (index_mirr != -1 && index_mirr != index) { @@ -1610,7 +1610,7 @@ static bool wpaint_stroke_test_start(bContext *C, wmOperator *op, const float mo int i; bDeformGroup *dg; - if (me->editflag & ME_EDIT_MIRROR_X) { + if (me->editflag & ME_EDIT_VERTEX_GROUPS_X_SYMMETRY) { BKE_object_defgroup_mirror_selection( ob, defbase_tot, defbase_sel, defbase_sel, &defbase_tot_sel); } @@ -2173,7 +2173,8 @@ static void wpaint_paint_leaves(bContext *C, /* NOTE: current mirroring code cannot be run in parallel */ TaskParallelSettings settings; - BKE_pbvh_parallel_range_settings(&settings, !(me->editflag & ME_EDIT_MIRROR_X), totnode); + BKE_pbvh_parallel_range_settings( + &settings, !(me->flag & ME_EDIT_VERTEX_GROUPS_X_SYMMETRY), totnode); switch ((eBrushWeightPaintTool)brush->weightpaint_tool) { case WPAINT_TOOL_AVERAGE: @@ -2291,7 +2292,7 @@ static void wpaint_do_symmetrical_brush_actions( Mesh *me = ob->data; SculptSession *ss = ob->sculpt; StrokeCache *cache = ss->cache; - const char symm = wp->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL; + const char symm = SCULPT_mesh_symmetry_xyz_get(ob); int i = 0; /* initial stroke */ @@ -3311,7 +3312,7 @@ static void vpaint_do_symmetrical_brush_actions( Mesh *me = ob->data; SculptSession *ss = ob->sculpt; StrokeCache *cache = ss->cache; - const char symm = vp->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL; + const char symm = SCULPT_mesh_symmetry_xyz_get(ob); int i = 0; /* initial stroke */ diff --git a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c index 9b8252e1add..eea79bad789 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c @@ -120,8 +120,13 @@ static int weight_from_bones_exec(bContext *C, wmOperator *op) Mesh *me = ob->data; int type = RNA_enum_get(op->ptr, "type"); - ED_object_vgroup_calc_from_armature( - op->reports, depsgraph, scene, ob, armob, type, (me->editflag & ME_EDIT_MIRROR_X)); + ED_object_vgroup_calc_from_armature(op->reports, + depsgraph, + scene, + ob, + armob, + type, + (me->editflag & ME_EDIT_VERTEX_GROUPS_X_SYMMETRY)); DEG_id_tag_update(&me->id, 0); DEG_relations_tag_update(CTX_data_main(C)); @@ -232,7 +237,7 @@ static int weight_sample_invoke(bContext *C, wmOperator *op, const wmEvent *even vc.obact, defbase_tot, &defbase_tot_sel); if (defbase_tot_sel > 1) { - if (me->editflag & ME_EDIT_MIRROR_X) { + if (me->editflag & ME_EDIT_VERTEX_GROUPS_X_SYMMETRY) { BKE_object_defgroup_mirror_selection( vc.obact, defbase_tot, defbase_sel, defbase_sel, &defbase_tot_sel); } @@ -458,7 +463,7 @@ static bool weight_paint_set(Object *ob, float paintweight) vgroup_active = ob->actdef - 1; /* if mirror painting, find the other group */ - if (me->editflag & ME_EDIT_MIRROR_X) { + if (me->editflag & ME_EDIT_VERTEX_GROUPS_X_SYMMETRY) { vgroup_mirror = ED_wpaint_mirror_vgroup_ensure(ob, vgroup_active); } @@ -486,7 +491,7 @@ static bool weight_paint_set(Object *ob, float paintweight) dw_prev->weight = dw->weight; /* set the undo weight */ dw->weight = paintweight; - if (me->editflag & ME_EDIT_MIRROR_X) { /* x mirror painting */ + if (me->editflag & ME_EDIT_VERTEX_GROUPS_X_SYMMETRY) { /* x mirror painting */ int j = mesh_get_x_mirror_vert(ob, NULL, vidx, topology); if (j >= 0) { /* copy, not paint again */ diff --git a/source/blender/editors/sculpt_paint/paint_vertex_weight_utils.c b/source/blender/editors/sculpt_paint/paint_vertex_weight_utils.c index a483f63bc06..dc777572858 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_weight_utils.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_weight_utils.c @@ -118,7 +118,7 @@ bool ED_wpaint_ensure_data(bContext *C, } if (flag & WPAINT_ENSURE_MIRROR) { - if (me->editflag & ME_EDIT_MIRROR_X) { + if (me->editflag & ME_EDIT_VERTEX_GROUPS_X_SYMMETRY) { int mirror = ED_wpaint_mirror_vgroup_ensure(ob, ob->actdef - 1); if (vgroup_index) { vgroup_index->mirror = mirror; diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index a577760cf9b..0b4f853b677 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -296,6 +296,12 @@ float *SCULPT_brush_deform_target_vertex_co_get(SculptSession *ss, return iter->co; } +char SCULPT_mesh_symmetry_xyz_get(Object *object) +{ + const Mesh *mesh = BKE_mesh_from_object(object); + return mesh->symmetry; +} + /* Sculpt Face Sets and Visibility. */ int SCULPT_active_face_set_get(SculptSession *ss) @@ -1057,7 +1063,7 @@ void SCULPT_floodfill_add_initial_with_symmetry( Sculpt *sd, Object *ob, SculptSession *ss, SculptFloodFill *flood, int index, float radius) { /* Add active vertex and symmetric vertices to the queue. */ - const char symm = sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL; + const char symm = SCULPT_mesh_symmetry_xyz_get(ob); for (char i = 0; i <= symm; ++i) { if (SCULPT_is_symmetry_iteration_valid(i, symm)) { int v = -1; @@ -1081,7 +1087,7 @@ void SCULPT_floodfill_add_active( Sculpt *sd, Object *ob, SculptSession *ss, SculptFloodFill *flood, float radius) { /* Add active vertex and symmetric vertices to the queue. */ - const char symm = sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL; + const char symm = SCULPT_mesh_symmetry_xyz_get(ob); for (char i = 0; i <= symm; ++i) { if (SCULPT_is_symmetry_iteration_valid(i, symm)) { int v = -1; @@ -6247,7 +6253,7 @@ static void do_symmetrical_brush_actions(Sculpt *sd, Brush *brush = BKE_paint_brush(&sd->paint); SculptSession *ss = ob->sculpt; StrokeCache *cache = ss->cache; - const char symm = sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL; + const char symm = SCULPT_mesh_symmetry_xyz_get(ob); float feather = calc_symmetry_feather(sd, ss->cache); diff --git a/source/blender/editors/sculpt_paint/sculpt_automasking.c b/source/blender/editors/sculpt_paint/sculpt_automasking.c index eef090f484e..241f1167316 100644 --- a/source/blender/editors/sculpt_paint/sculpt_automasking.c +++ b/source/blender/editors/sculpt_paint/sculpt_automasking.c @@ -213,7 +213,7 @@ static float *SCULPT_topology_automasking_init(Sculpt *sd, Object *ob, float *au .automask_factor = automask_factor, .radius = ss->cache->radius, .use_radius = sculpt_automasking_is_constrained_by_radius(brush), - .symm = sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL, + .symm = SCULPT_mesh_symmetry_xyz_get(ob), }; copy_v3_v3(fdata.location, SCULPT_active_vertex_co_get(ss)); SCULPT_floodfill_execute(ss, &flood, automask_floodfill_cb, &fdata); diff --git a/source/blender/editors/sculpt_paint/sculpt_boundary.c b/source/blender/editors/sculpt_paint/sculpt_boundary.c index b07dd18b6fc..ce8b63ce4f8 100644 --- a/source/blender/editors/sculpt_paint/sculpt_boundary.c +++ b/source/blender/editors/sculpt_paint/sculpt_boundary.c @@ -648,7 +648,7 @@ static void do_boundary_brush_bend_task_cb_ex(void *__restrict userdata, SculptSession *ss = data->ob->sculpt; const int symm_area = ss->cache->mirror_symmetry_pass; SculptBoundary *boundary = ss->cache->boundaries[symm_area]; - const ePaintSymmetryFlags symm = data->sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL; + const ePaintSymmetryFlags symm = SCULPT_mesh_symmetry_xyz_get(data->ob); const Brush *brush = data->brush; const float strength = ss->cache->bstrength; @@ -699,7 +699,7 @@ static void do_boundary_brush_slide_task_cb_ex(void *__restrict userdata, SculptSession *ss = data->ob->sculpt; const int symm_area = ss->cache->mirror_symmetry_pass; SculptBoundary *boundary = ss->cache->boundaries[symm_area]; - const ePaintSymmetryFlags symm = data->sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL; + const ePaintSymmetryFlags symm = SCULPT_mesh_symmetry_xyz_get(data->ob); const Brush *brush = data->brush; const float strength = ss->cache->bstrength; @@ -741,7 +741,7 @@ static void do_boundary_brush_inflate_task_cb_ex(void *__restrict userdata, SculptSession *ss = data->ob->sculpt; const int symm_area = ss->cache->mirror_symmetry_pass; SculptBoundary *boundary = ss->cache->boundaries[symm_area]; - const ePaintSymmetryFlags symm = data->sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL; + const ePaintSymmetryFlags symm = SCULPT_mesh_symmetry_xyz_get(data->ob); const Brush *brush = data->brush; const float strength = ss->cache->bstrength; @@ -785,7 +785,7 @@ static void do_boundary_brush_grab_task_cb_ex(void *__restrict userdata, SculptSession *ss = data->ob->sculpt; const int symm_area = ss->cache->mirror_symmetry_pass; SculptBoundary *boundary = ss->cache->boundaries[symm_area]; - const ePaintSymmetryFlags symm = data->sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL; + const ePaintSymmetryFlags symm = SCULPT_mesh_symmetry_xyz_get(data->ob); const Brush *brush = data->brush; const float strength = ss->cache->bstrength; @@ -825,7 +825,7 @@ static void do_boundary_brush_twist_task_cb_ex(void *__restrict userdata, SculptSession *ss = data->ob->sculpt; const int symm_area = ss->cache->mirror_symmetry_pass; SculptBoundary *boundary = ss->cache->boundaries[symm_area]; - const ePaintSymmetryFlags symm = data->sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL; + const ePaintSymmetryFlags symm = SCULPT_mesh_symmetry_xyz_get(data->ob); const Brush *brush = data->brush; const float strength = ss->cache->bstrength; diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h index 53641dae447..bc88793b993 100644 --- a/source/blender/editors/sculpt_paint/sculpt_intern.h +++ b/source/blender/editors/sculpt_paint/sculpt_intern.h @@ -88,6 +88,9 @@ float SCULPT_raycast_init(struct ViewContext *vc, float ray_normal[3], bool original); +/* Symmetry */ +char SCULPT_mesh_symmetry_xyz_get(Object *object); + /* Sculpt PBVH abstraction API */ void SCULPT_vertex_random_access_ensure(struct SculptSession *ss); diff --git a/source/blender/editors/sculpt_paint/sculpt_mask_expand.c b/source/blender/editors/sculpt_paint/sculpt_mask_expand.c index 0ae9baf7e2e..e403bada316 100644 --- a/source/blender/editors/sculpt_paint/sculpt_mask_expand.c +++ b/source/blender/editors/sculpt_paint/sculpt_mask_expand.c @@ -213,7 +213,7 @@ static int sculpt_mask_expand_modal(bContext *C, wmOperator *op, const wmEvent * /* Pivot position. */ if (RNA_boolean_get(op->ptr, "update_pivot")) { - const char symm = sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL; + const char symm = SCULPT_mesh_symmetry_xyz_get(ob); const float threshold = 0.2f; float avg[3]; int total = 0; diff --git a/source/blender/editors/sculpt_paint/sculpt_pose.c b/source/blender/editors/sculpt_paint/sculpt_pose.c index e53e33c1186..4081e7a962f 100644 --- a/source/blender/editors/sculpt_paint/sculpt_pose.c +++ b/source/blender/editors/sculpt_paint/sculpt_pose.c @@ -230,7 +230,7 @@ static void pose_brush_grow_factor_task_cb_ex(void *__restrict userdata, SculptThreadedTaskData *data = userdata; PoseGrowFactorTLSData *gftd = tls->userdata_chunk; SculptSession *ss = data->ob->sculpt; - const char symm = data->sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL; + const char symm = SCULPT_mesh_symmetry_xyz_get(data->ob); PBVHVertexIter vd; BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { @@ -561,7 +561,7 @@ void SCULPT_pose_calc_pose_data(Sculpt *sd, PoseFloodFillData fdata = { .radius = radius, - .symm = sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL, + .symm = SCULPT_mesh_symmetry_xyz_get(ob), .pose_factor = r_pose_factor, .tot_co = 0, }; @@ -777,7 +777,7 @@ static SculptPoseIKChain *pose_ik_chain_init_face_sets( PoseFloodFillData fdata = { .radius = radius, - .symm = sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL, + .symm = SCULPT_mesh_symmetry_xyz_get(ob), .pose_factor = ik_chain->segments[s].weights, .tot_co = 0, .fallback_count = 0, @@ -1134,7 +1134,7 @@ void SCULPT_do_pose_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) { SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); - const ePaintSymmetryFlags symm = sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL; + const ePaintSymmetryFlags symm = SCULPT_mesh_symmetry_xyz_get(ob); /* The pose brush applies all enabled symmetry axis in a single iteration, so the rest can be * ignored. */ diff --git a/source/blender/editors/sculpt_paint/sculpt_transform.c b/source/blender/editors/sculpt_paint/sculpt_transform.c index b52b04eba3a..479f70b5ff1 100644 --- a/source/blender/editors/sculpt_paint/sculpt_transform.c +++ b/source/blender/editors/sculpt_paint/sculpt_transform.c @@ -124,7 +124,7 @@ void ED_sculpt_update_modal_transform(struct bContext *C) Object *ob = CTX_data_active_object(C); SculptSession *ss = ob->sculpt; Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); - const char symm = sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL; + const char symm = SCULPT_mesh_symmetry_xyz_get(ob); SCULPT_vertex_random_access_ensure(ss); BKE_sculpt_update_object_for_edit(depsgraph, ob, false, false, false); @@ -243,12 +243,11 @@ static EnumPropertyItem prop_sculpt_pivot_position_types[] = { static int sculpt_set_pivot_position_exec(bContext *C, wmOperator *op) { - Sculpt *sd = CTX_data_tool_settings(C)->sculpt; Object *ob = CTX_data_active_object(C); SculptSession *ss = ob->sculpt; ARegion *region = CTX_wm_region(C); Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - const char symm = sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL; + const char symm = SCULPT_mesh_symmetry_xyz_get(ob); int mode = RNA_enum_get(op->ptr, "mode"); -- cgit v1.2.3