Weight Smooth: remove source option
authorCampbell Barton <ideasman42@gmail.com>
Thu, 7 Sep 2017 04:12:11 +0000 (14:12 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 7 Sep 2017 04:14:42 +0000 (14:14 +1000)
Use current selection mode instead of an operator option.

source/blender/editors/object/object_vgroup.c

index d9ad037daea62f5f1aa25dcc332aa2802de50cf3..19893c79db4f7e24c98d02140b6100b671d3cf41 100644 (file)
@@ -1715,17 +1715,11 @@ static void vgroup_invert_subset(Object *ob,
        }
 }
 
-enum {
-       WEIGHT_SMOOTH_ALL = -1,
-       WEIGHT_SMOOTH_DESELECT = false,
-       WEIGHT_SMOOTH_SELECT = true,
-};
-
 static void vgroup_smooth_subset(
         Object *ob, const bool *vgroup_validmap, const int vgroup_tot,
         const int subset_count,
         const float fac, const int repeat,
-        const float fac_expand, const int source)
+        const float fac_expand)
 {
        const float ifac = 1.0f - fac;
        MDeformVert **dvert_array = NULL;
@@ -1733,6 +1727,8 @@ static void vgroup_smooth_subset(
        int *vgroup_subset_map = BLI_array_alloca(vgroup_subset_map, subset_count);
        float *vgroup_subset_weights = BLI_array_alloca(vgroup_subset_weights, subset_count);
        const bool use_mirror = (ob->type == OB_MESH) ? (((Mesh *)ob->data)->editflag & ME_EDIT_MIRROR_X) != 0 : false;
+       const bool use_select = vertex_group_use_vert_sel(ob);
+       const bool use_hide = use_select;
 
        const int    expand_sign = signum_i(fac_expand);
        const float  expand = fabsf(fac_expand);
@@ -1776,19 +1772,26 @@ static void vgroup_smooth_subset(
        verts_used = MEM_mallocN(sizeof(*verts_used) * dvert_tot, __func__);
        STACK_INIT(verts_used, dvert_tot);
 
+#define IS_BM_VERT_READ(v) \
+       (use_hide ? (BM_elem_flag_test(v, BM_ELEM_HIDDEN) == 0) : true)
+#define IS_BM_VERT_WRITE(v) \
+       (use_select ? (BM_elem_flag_test(v, BM_ELEM_SELECT) != 0) : true)
+
+#define IS_ME_VERT_READ(v) \
+       (use_hide ? (((v)->flag & ME_HIDE) == 0) : true)
+#define IS_ME_VERT_WRITE(v) \
+       (use_select ? (((v)->flag & SELECT) != 0) : true)
 
        /* initialize used verts */
        if (bm) {
                for (int i = 0; i < dvert_tot; i++) {
                        BMVert *v = BM_vert_at_index(bm, i);
-                       if (BM_elem_flag_test(v, BM_ELEM_SELECT)) {
+                       if (IS_BM_VERT_WRITE(v)) {
                                BMIter eiter;
                                BMEdge *e;
                                BM_ITER_ELEM (e, &eiter, v, BM_EDGES_OF_VERT) {
                                        BMVert *v_other = BM_edge_other_vert(e, v);
-                                       if ((source == WEIGHT_SMOOTH_ALL) ||
-                                           (source == (BM_elem_flag_test(v_other, BM_ELEM_SELECT) != 0)))
-                                       {
+                                       if (IS_BM_VERT_READ(v_other)) {
                                                STACK_PUSH(verts_used, i);
                                                break;
                                        }
@@ -1799,13 +1802,11 @@ static void vgroup_smooth_subset(
        else {
                for (int i = 0; i < dvert_tot; i++) {
                        const MVert *v = &me->mvert[i];
-                       if (v->flag & SELECT) {
+                       if (IS_ME_VERT_WRITE(v)) {
                                for (int j = 0; j < emap[i].count; j++) {
                                        const MEdge *e = &me->medge[emap[i].indices[j]];
                                        const MVert *v_other = &me->mvert[(e->v1 == i) ? e->v2 : e->v1];
-                                       if ((source == WEIGHT_SMOOTH_ALL) ||
-                                           (source == ((v_other->flag & SELECT) != 0)))
-                                       {
+                                       if (IS_ME_VERT_READ(v_other)) {
                                                STACK_PUSH(verts_used, i);
                                                break;
                                        }
@@ -1858,13 +1859,11 @@ static void vgroup_smooth_subset(
                                        BMEdge *e;
 
                                        /* checked already */
-                                       BLI_assert(BM_elem_flag_test(v, BM_ELEM_SELECT));
+                                       BLI_assert(IS_BM_VERT_WRITE(v));
 
                                        BM_ITER_ELEM (e, &eiter, v, BM_EDGES_OF_VERT) {
                                                BMVert *v_other = BM_edge_other_vert(e, v);
-                                               if ((source == WEIGHT_SMOOTH_ALL) ||
-                                                   (source == (BM_elem_flag_test(v_other, BM_ELEM_SELECT) != 0)))
-                                               {
+                                               if (IS_BM_VERT_READ(v_other)) {
                                                        const int i_other = BM_elem_index_get(v_other);
 
                                                        WEIGHT_ACCUMULATE;
@@ -1875,16 +1874,14 @@ static void vgroup_smooth_subset(
                                        int j;
 
                                        /* checked already */
-                                       BLI_assert(me->mvert[i].flag & SELECT);
+                                       BLI_assert(IS_ME_VERT_WRITE(&me->mvert[i]));
 
                                        for (j = 0; j < emap[i].count; j++) {
                                                MEdge *e = &me->medge[emap[i].indices[j]];
                                                const int i_other = (e->v1 == i ? e->v2 : e->v1);
                                                MVert *v_other = &me->mvert[i_other];
 
-                                               if ((source == WEIGHT_SMOOTH_ALL) ||
-                                                   (source == ((v_other->flag & SELECT) != 0)))
-                                               {
+                                               if (IS_ME_VERT_READ(v_other)) {
                                                        WEIGHT_ACCUMULATE;
                                                }
                                        }
@@ -1908,6 +1905,11 @@ static void vgroup_smooth_subset(
                ED_vgroup_parray_from_weight_array(dvert_array, dvert_tot, weight_accum_prev, def_nr, true);
        }
 
+#undef IS_BM_VERT_READ
+#undef IS_BM_VERT_WRITE
+#undef IS_ME_VERT_READ
+#undef IS_ME_VERT_WRITE
+
        MEM_freeN(weight_accum_curr);
        MEM_freeN(weight_accum_prev);
        MEM_freeN(verts_used);
@@ -2501,7 +2503,7 @@ static int UNUSED_FUNCTION(vertex_group_poll_edit) (bContext *C)
 }
 
 /* editmode _or_ weight paint vertex sel */
-static int vertex_group_vert_select_poll_ex(bContext *C, const short ob_type_flag)
+static int vertex_group_vert_poll_ex(bContext *C, const bool needs_select, const short ob_type_flag)
 {
        Object *ob = ED_object_context(C);
        ID *data = (ob) ? ob->data : NULL;
@@ -2517,12 +2519,17 @@ static int vertex_group_vert_select_poll_ex(bContext *C, const short ob_type_fla
                return true;
        }
        else if (ob->mode & OB_MODE_WEIGHT_PAINT) {
-               if (BKE_object_is_in_wpaint_select_vert(ob)) {
-                       return true;
+               if (needs_select) {
+                       if (BKE_object_is_in_wpaint_select_vert(ob)) {
+                               return true;
+                       }
+                       else {
+                               CTX_wm_operator_poll_msg_set(C, "Vertex select needs to be enabled in weight paint mode");
+                               return false;
+                       }
                }
                else {
-                       CTX_wm_operator_poll_msg_set(C, "Vertex select needs to be enabled in weight paint mode");
-                       return false;
+                       return true;
                }
        }
        else {
@@ -2530,15 +2537,31 @@ static int vertex_group_vert_select_poll_ex(bContext *C, const short ob_type_fla
        }
 }
 
+#if 0
+static int vertex_group_vert_poll(bContext *C)
+{
+       return vertex_group_vert_poll_ex(C, false, 0);
+}
+#endif
+
+
+static int vertex_group_mesh_vert_poll(bContext *C)
+{
+       return vertex_group_vert_poll_ex(C, false, (1 << OB_MESH));
+}
+
 static int vertex_group_vert_select_poll(bContext *C)
 {
-       return vertex_group_vert_select_poll_ex(C, 0);
+       return vertex_group_vert_poll_ex(C, true, 0);
 }
 
+#if 0
 static int vertex_group_mesh_vert_select_poll(bContext *C)
 {
-       return vertex_group_vert_select_poll_ex(C, (1 << OB_MESH));
+       return vertex_group_vert_poll_ex(C, true, (1 << OB_MESH));
 }
+#endif
+
 
 /* editmode _or_ weight paint vertex sel and active group unlocked */
 static int vertex_group_vert_select_unlocked_poll(bContext *C)
@@ -3085,13 +3108,12 @@ static int vertex_group_smooth_exec(bContext *C, wmOperator *op)
        const float fac = RNA_float_get(op->ptr, "factor");
        const int repeat = RNA_int_get(op->ptr, "repeat");
        eVGroupSelect subset_type  = RNA_enum_get(op->ptr, "group_select_mode");
-       const int source = RNA_enum_get(op->ptr, "source");
        const float fac_expand = RNA_float_get(op->ptr, "expand");
 
        int subset_count, vgroup_tot;
 
        const bool *vgroup_validmap = BKE_object_defgroup_subset_from_select_type(ob, subset_type, &vgroup_tot, &subset_count);
-       vgroup_smooth_subset(ob, vgroup_validmap, vgroup_tot, subset_count, fac, repeat, fac_expand, source);
+       vgroup_smooth_subset(ob, vgroup_validmap, vgroup_tot, subset_count, fac, repeat, fac_expand);
        MEM_freeN((void *)vgroup_validmap);
 
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
@@ -3103,20 +3125,13 @@ static int vertex_group_smooth_exec(bContext *C, wmOperator *op)
 
 void OBJECT_OT_vertex_group_smooth(wmOperatorType *ot)
 {
-       static EnumPropertyItem smooth_source_item[] = {
-               {WEIGHT_SMOOTH_ALL, "ALL", 0, "All", ""},
-               {WEIGHT_SMOOTH_SELECT, "SELECT", 0, "Only Selected", ""},
-               {WEIGHT_SMOOTH_DESELECT, "DESELECT", 0, "Only Deselected", ""},
-               {0, NULL, 0, NULL, NULL}
-       };
-
        /* identifiers */
        ot->name = "Smooth Vertex Weights";
        ot->idname = "OBJECT_OT_vertex_group_smooth";
        ot->description = "Smooth weights for selected vertices";
 
        /* api callbacks */
-       ot->poll = vertex_group_mesh_vert_select_poll;
+       ot->poll = vertex_group_mesh_vert_poll;
        ot->exec = vertex_group_smooth_exec;
 
        /* flags */
@@ -3127,7 +3142,6 @@ void OBJECT_OT_vertex_group_smooth(wmOperatorType *ot)
        RNA_def_int(ot->srna, "repeat", 1, 1, 10000, "Iterations", "", 1, 200);
 
        RNA_def_float(ot->srna, "expand", 0.0f, -1.0f, 1.0, "Expand/Contract", "Expand/contract weights", -1.0f, 1.0f);
-       RNA_def_enum(ot->srna, "source", smooth_source_item, -1, "Source", "Vertices to mix with");
 }
 
 static int vertex_group_clean_exec(bContext *C, wmOperator *op)