diff options
Diffstat (limited to 'source/blender/editors/object/object_vgroup.c')
-rw-r--r-- | source/blender/editors/object/object_vgroup.c | 330 |
1 files changed, 188 insertions, 142 deletions
diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 3c406764157..c6c20182ac3 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -50,7 +50,7 @@ #include "BLI_blenlib.h" #include "BLI_utildefines.h" #include "BLI_linklist_stack.h" -#include "BLI_stackdefines.h" +#include "BLI_utildefines_stack.h" #include "BKE_context.h" @@ -238,6 +238,9 @@ bool ED_vgroup_parray_alloc(ID *id, MDeformVert ***dvert_arr, int *dvert_tot, co } return false; } + + default: + break; } } @@ -250,9 +253,10 @@ bool ED_vgroup_parray_alloc(ID *id, MDeformVert ***dvert_arr, int *dvert_tot, co * * \note \a dvert_array has mirrored weights filled in, incase cleanup operations are needed on both. */ -void ED_vgroup_parray_mirror_sync(Object *ob, - MDeformVert **dvert_array, const int dvert_tot, - const bool *vgroup_validmap, const int vgroup_tot) +void ED_vgroup_parray_mirror_sync( + Object *ob, + MDeformVert **dvert_array, const int dvert_tot, + const bool *vgroup_validmap, const int vgroup_tot) { BMEditMesh *em = BKE_editmesh_from_object(ob); MDeformVert **dvert_array_all = NULL; @@ -295,8 +299,9 @@ void ED_vgroup_parray_mirror_sync(Object *ob, * * similar to #ED_vgroup_parray_mirror_sync but only fill in mirror points. */ -void ED_vgroup_parray_mirror_assign(Object *ob, - MDeformVert **dvert_array, const int dvert_tot) +void ED_vgroup_parray_mirror_assign( + Object *ob, + MDeformVert **dvert_array, const int dvert_tot) { BMEditMesh *em = BKE_editmesh_from_object(ob); MDeformVert **dvert_array_all = NULL; @@ -327,9 +332,10 @@ void ED_vgroup_parray_mirror_assign(Object *ob, MEM_freeN(dvert_array_all); } -void ED_vgroup_parray_remove_zero(MDeformVert **dvert_array, const int dvert_tot, - const bool *vgroup_validmap, const int vgroup_tot, - const float epsilon, const bool keep_single) +void ED_vgroup_parray_remove_zero( + MDeformVert **dvert_array, const int dvert_tot, + const bool *vgroup_validmap, const int vgroup_tot, + const float epsilon, const bool keep_single) { MDeformVert *dv; int i; @@ -479,9 +485,10 @@ void ED_vgroup_parray_from_weight_array( /* TODO, cache flip data to speedup calls within a loop. */ -static void mesh_defvert_mirror_update_internal(Object *ob, - MDeformVert *dvert_dst, MDeformVert *dvert_src, - const int def_nr) +static void mesh_defvert_mirror_update_internal( + Object *ob, + MDeformVert *dvert_dst, MDeformVert *dvert_src, + const int def_nr) { if (def_nr == -1) { /* all vgroups, add groups where neded */ @@ -499,8 +506,9 @@ static void mesh_defvert_mirror_update_internal(Object *ob, } } -static void ED_mesh_defvert_mirror_update_em(Object *ob, BMVert *eve, int def_nr, int vidx, - const int cd_dvert_offset) +static void ED_mesh_defvert_mirror_update_em( + Object *ob, BMVert *eve, int def_nr, int vidx, + const int cd_dvert_offset) { Mesh *me = ob->data; BMEditMesh *em = me->edit_btmesh; @@ -663,7 +671,7 @@ static void vgroup_copy_active_to_sel(Object *ob, eVGroupSelect subset_type) /***********************Start weight transfer (WT)*********************************/ -static EnumPropertyItem WT_vertex_group_select_item[] = { +static const EnumPropertyItem WT_vertex_group_select_item[] = { {WT_VGROUP_ACTIVE, "ACTIVE", 0, "Active Group", "The active Vertex Group"}, {WT_VGROUP_BONE_SELECT, @@ -675,7 +683,7 @@ static EnumPropertyItem WT_vertex_group_select_item[] = { {0, NULL, 0, NULL, NULL} }; -EnumPropertyItem *ED_object_vgroup_selection_itemf_helper( +const EnumPropertyItem *ED_object_vgroup_selection_itemf_helper( const bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free, const unsigned int selection_mask) { @@ -683,9 +691,10 @@ EnumPropertyItem *ED_object_vgroup_selection_itemf_helper( EnumPropertyItem *item = NULL; int totitem = 0; - - if (!C) /* needed for docs and i18n tools */ + if (C == NULL) { + /* needed for docs and i18n tools */ return WT_vertex_group_select_item; + } ob = CTX_data_active_object(C); if (selection_mask & (1 << WT_VGROUP_ACTIVE)) @@ -707,26 +716,30 @@ EnumPropertyItem *ED_object_vgroup_selection_itemf_helper( return item; } -static EnumPropertyItem *rna_vertex_group_with_single_itemf(bContext *C, PointerRNA *ptr, - PropertyRNA *prop, bool *r_free) +static const EnumPropertyItem *rna_vertex_group_with_single_itemf( + bContext *C, PointerRNA *ptr, + PropertyRNA *prop, bool *r_free) { return ED_object_vgroup_selection_itemf_helper(C, ptr, prop, r_free, WT_VGROUP_MASK_ALL); } -static EnumPropertyItem *rna_vertex_group_select_itemf(bContext *C, PointerRNA *ptr, - PropertyRNA *prop, bool *r_free) +static const EnumPropertyItem *rna_vertex_group_select_itemf( + bContext *C, PointerRNA *ptr, + PropertyRNA *prop, bool *r_free) { - return ED_object_vgroup_selection_itemf_helper(C, ptr, prop, r_free, WT_VGROUP_MASK_ALL & ~(1 << WT_VGROUP_ACTIVE)); + return ED_object_vgroup_selection_itemf_helper( + C, ptr, prop, r_free, WT_VGROUP_MASK_ALL & ~(1 << WT_VGROUP_ACTIVE)); } static void vgroup_operator_subset_select_props(wmOperatorType *ot, bool use_active) { PropertyRNA *prop; - prop = RNA_def_enum(ot->srna, - "group_select_mode", DummyRNA_NULL_items, - use_active ? WT_VGROUP_ACTIVE : WT_VGROUP_ALL, "Subset", - "Define which subset of Groups shall be used"); + prop = RNA_def_enum( + ot->srna, + "group_select_mode", DummyRNA_NULL_items, + use_active ? WT_VGROUP_ACTIVE : WT_VGROUP_ALL, "Subset", + "Define which subset of Groups shall be used"); if (use_active) { RNA_def_enum_funcs(prop, rna_vertex_group_with_single_itemf); @@ -743,9 +756,10 @@ static void vgroup_operator_subset_select_props(wmOperatorType *ot, bool use_act /* for Mesh in Object mode */ /* allows editmode for Lattice */ -static void ED_vgroup_nr_vert_add(Object *ob, - const int def_nr, const int vertnum, - const float weight, const int assignmode) +static void ED_vgroup_nr_vert_add( + Object *ob, + const int def_nr, const int vertnum, + const float weight, const int assignmode) { /* add the vert to the deform group with the * specified number @@ -1173,7 +1187,7 @@ static int *getSurroundingVerts(Mesh *me, int vert, int *count) } /* Append a and b verts to array, if not yet present. */ - k = BLI_array_count(verts); + k = BLI_array_len(verts); /* XXX Maybe a == b is enough? */ while (k-- && !(a == b && a == -1)) { if (verts[k] == a) @@ -1195,7 +1209,7 @@ static int *getSurroundingVerts(Mesh *me, int vert, int *count) } /* Do not free the array! */ - *count = BLI_array_count(verts); + *count = BLI_array_len(verts); return verts; } @@ -1216,9 +1230,10 @@ static void getSingleCoordinate(MVert *points, int count, float coord[3]) * compute the amount of vertical distance relative to the plane and store it in dists, * then get the horizontal and vertical change and store them in changes */ -static void getVerticalAndHorizontalChange(const float norm[3], float d, const float coord[3], - const float start[3], float distToStart, - float *end, float (*changes)[2], float *dists, int index) +static void getVerticalAndHorizontalChange( + const float norm[3], float d, const float coord[3], + const float start[3], float distToStart, + float *end, float (*changes)[2], float *dists, int index) { /* A = Q - ((Q - P).N)N * D = (a * x0 + b * y0 +c * z0 + d) */ @@ -1269,8 +1284,9 @@ static DerivedMesh *dm_deform_recalc(Scene *scene, Object *ob) * norm and d are the plane's properties for the equation: ax + by + cz + d = 0 * coord is a point on the plane */ -static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, int index, float norm[3], - float coord[3], float d, float distToBe, float strength, float cp) +static void moveCloserToDistanceFromPlane( + Scene *scene, Object *ob, Mesh *me, int index, float norm[3], + float coord[3], float d, float distToBe, float strength, float cp) { DerivedMesh *dm; MDeformWeight *dw; @@ -1490,9 +1506,10 @@ static void vgroup_fix(Scene *scene, Object *ob, float distToBe, float strength, } } -static void vgroup_levels_subset(Object *ob, const bool *vgroup_validmap, const int vgroup_tot, - const int UNUSED(subset_count), - const float offset, const float gain) +static void vgroup_levels_subset( + Object *ob, const bool *vgroup_validmap, const int vgroup_tot, + const int UNUSED(subset_count), + const float offset, const float gain) { MDeformWeight *dw; MDeformVert *dv, **dvert_array = NULL; @@ -1527,8 +1544,9 @@ static void vgroup_levels_subset(Object *ob, const bool *vgroup_validmap, const } if (use_mirror && use_vert_sel) { - ED_vgroup_parray_mirror_sync(ob, dvert_array, dvert_tot, - vgroup_validmap, vgroup_tot); + ED_vgroup_parray_mirror_sync( + ob, dvert_array, dvert_tot, + vgroup_validmap, vgroup_tot); } MEM_freeN(dvert_array); @@ -1585,12 +1603,14 @@ static bool vgroup_normalize_all( /* in case its not selected */ if ((dv = dvert_array[i])) { if (lock_flags) { - defvert_normalize_lock_map(dv, vgroup_validmap, vgroup_tot, - lock_flags, defbase_tot); + defvert_normalize_lock_map( + dv, vgroup_validmap, vgroup_tot, + lock_flags, defbase_tot); } else if (lock_active) { - defvert_normalize_lock_single(dv, vgroup_validmap, vgroup_tot, - def_nr); + defvert_normalize_lock_single( + dv, vgroup_validmap, vgroup_tot, + def_nr); } else { defvert_normalize_subset(dv, vgroup_validmap, vgroup_tot); @@ -1620,7 +1640,7 @@ enum { VGROUP_INVERT }; -static EnumPropertyItem vgroup_lock_actions[] = { +static const EnumPropertyItem vgroup_lock_actions[] = { {VGROUP_TOGGLE, "TOGGLE", 0, "Toggle", "Unlock all vertex groups if there is at least one locked group, lock all in other case"}, {VGROUP_LOCK, "LOCK", 0, "Lock", "Lock all vertex groups"}, {VGROUP_UNLOCK, "UNLOCK", 0, "Unlock", "Unlock all vertex groups"}, @@ -1657,9 +1677,10 @@ static void vgroup_lock_all(Object *ob, int action) } } -static void vgroup_invert_subset(Object *ob, - const bool *vgroup_validmap, const int vgroup_tot, - const int UNUSED(subset_count), const bool auto_assign, const bool auto_remove) +static void vgroup_invert_subset( + Object *ob, + const bool *vgroup_validmap, const int vgroup_tot, + const int UNUSED(subset_count), const bool auto_assign, const bool auto_remove) { MDeformWeight *dw; MDeformVert *dv, **dvert_array = NULL; @@ -1698,31 +1719,27 @@ static void vgroup_invert_subset(Object *ob, } if (use_mirror && use_vert_sel) { - ED_vgroup_parray_mirror_sync(ob, dvert_array, dvert_tot, - vgroup_validmap, vgroup_tot); + ED_vgroup_parray_mirror_sync( + ob, dvert_array, dvert_tot, + vgroup_validmap, vgroup_tot); } if (auto_remove) { - ED_vgroup_parray_remove_zero(dvert_array, dvert_tot, - vgroup_validmap, vgroup_tot, - 0.0f, false); + ED_vgroup_parray_remove_zero( + dvert_array, dvert_tot, + vgroup_validmap, vgroup_tot, + 0.0f, false); } MEM_freeN(dvert_array); } } -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; @@ -1730,6 +1747,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); @@ -1773,19 +1792,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; } @@ -1795,13 +1821,12 @@ static void vgroup_smooth_subset( } else { for (int i = 0; i < dvert_tot; i++) { - MVert *v = &me->mvert[i]; - if (v->flag & SELECT) { + const MVert *v = &me->mvert[i]; + if (IS_ME_VERT_WRITE(v)) { for (int j = 0; j < emap[i].count; j++) { - MVert *v_other = &me->mvert[emap[i].indices[j]]; - if ((source == WEIGHT_SMOOTH_ALL) || - (source == ((v_other->flag & SELECT) != 0))) - { + const MEdge *e = &me->medge[emap[i].indices[j]]; + const MVert *v_other = &me->mvert[(e->v1 == i) ? e->v2 : e->v1]; + if (IS_ME_VERT_READ(v_other)) { STACK_PUSH(verts_used, i); break; } @@ -1854,13 +1879,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; @@ -1871,16 +1894,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; } } @@ -1904,6 +1925,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); @@ -1922,8 +1948,9 @@ static void vgroup_smooth_subset( /* not so efficient to get 'dvert_array' again just so unselected verts are NULL'd */ if (use_mirror) { ED_vgroup_parray_alloc(ob->data, &dvert_array, &dvert_tot, true); - ED_vgroup_parray_mirror_sync(ob, dvert_array, dvert_tot, - vgroup_validmap, vgroup_tot); + ED_vgroup_parray_mirror_sync( + ob, dvert_array, dvert_tot, + vgroup_validmap, vgroup_tot); if (dvert_array) MEM_freeN(dvert_array); } @@ -1947,11 +1974,12 @@ static int inv_cmp_mdef_vert_weights(const void *a1, const void *a2) /* Used for limiting the number of influencing bones per vertex when exporting * skinned meshes. if all_deform_weights is True, limit all deform modifiers * to max_weights regardless of type, otherwise, only limit the number of influencing bones per vertex*/ -static int vgroup_limit_total_subset(Object *ob, - const bool *vgroup_validmap, - const int vgroup_tot, - const int subset_count, - const int max_weights) +static int vgroup_limit_total_subset( + Object *ob, + const bool *vgroup_validmap, + const int vgroup_tot, + const int subset_count, + const int max_weights) { MDeformVert *dv, **dvert_array = NULL; int i, dvert_tot = 0; @@ -2018,8 +2046,9 @@ static int vgroup_limit_total_subset(Object *ob, } -static void vgroup_clean_subset(Object *ob, const bool *vgroup_validmap, const int vgroup_tot, const int UNUSED(subset_count), - const float epsilon, const bool keep_single) +static void vgroup_clean_subset( + Object *ob, const bool *vgroup_validmap, const int vgroup_tot, const int UNUSED(subset_count), + const float epsilon, const bool keep_single) { MDeformVert **dvert_array = NULL; int dvert_tot = 0; @@ -2036,16 +2065,18 @@ static void vgroup_clean_subset(Object *ob, const bool *vgroup_validmap, const i ED_vgroup_parray_mirror_assign(ob, dvert_array, dvert_tot); } - ED_vgroup_parray_remove_zero(dvert_array, dvert_tot, - vgroup_validmap, vgroup_tot, - epsilon, keep_single); + ED_vgroup_parray_remove_zero( + dvert_array, dvert_tot, + vgroup_validmap, vgroup_tot, + epsilon, keep_single); MEM_freeN(dvert_array); } } -static void vgroup_quantize_subset(Object *ob, const bool *vgroup_validmap, const int vgroup_tot, const int UNUSED(subset_count), - const int steps) +static void vgroup_quantize_subset( + Object *ob, const bool *vgroup_validmap, const int vgroup_tot, const int UNUSED(subset_count), + const int steps) { MDeformVert **dvert_array = NULL; int dvert_tot = 0; @@ -2083,11 +2114,12 @@ static void vgroup_quantize_subset(Object *ob, const bool *vgroup_validmap, cons } } -static void dvert_mirror_op(MDeformVert *dvert, MDeformVert *dvert_mirr, - const char sel, const char sel_mirr, - const int *flip_map, const int flip_map_len, - const bool mirror_weights, const bool flip_vgroups, const bool all_vgroups, - const int act_vgroup) +static void dvert_mirror_op( + MDeformVert *dvert, MDeformVert *dvert_mirr, + const char sel, const char sel_mirr, + const int *flip_map, const int flip_map_len, + const bool mirror_weights, const bool flip_vgroups, const bool all_vgroups, + const int act_vgroup) { BLI_assert(sel || sel_mirr); @@ -2146,10 +2178,11 @@ static void dvert_mirror_op(MDeformVert *dvert, MDeformVert *dvert_mirr, /* TODO, vgroup locking */ /* TODO, face masking */ -void ED_vgroup_mirror(Object *ob, - const bool mirror_weights, const bool flip_vgroups, - const bool all_vgroups, const bool use_topology, - int *r_totmirr, int *r_totfail) +void ED_vgroup_mirror( + Object *ob, + const bool mirror_weights, const bool flip_vgroups, + const bool all_vgroups, const bool use_topology, + int *r_totmirr, int *r_totfail) { #define VGROUP_MIRR_OP \ @@ -2452,8 +2485,8 @@ static int vertex_group_poll(bContext *C) Object *ob = ED_object_context(C); ID *data = (ob) ? ob->data : NULL; - return (ob && !ID_IS_LINKED_DATABLOCK(ob) && - data && !ID_IS_LINKED_DATABLOCK(data) && + return (ob && !ID_IS_LINKED(ob) && + data && !ID_IS_LINKED(data) && OB_TYPE_SUPPORT_VGROUP(ob->type) && ob->defbase.first); } @@ -2462,8 +2495,8 @@ static int vertex_group_supported_poll(bContext *C) { Object *ob = ED_object_context(C); ID *data = (ob) ? ob->data : NULL; - return (ob && !ID_IS_LINKED_DATABLOCK(ob) && OB_TYPE_SUPPORT_VGROUP(ob->type) && - data && !ID_IS_LINKED_DATABLOCK(data)); + return (ob && !ID_IS_LINKED(ob) && OB_TYPE_SUPPORT_VGROUP(ob->type) && + data && !ID_IS_LINKED(data)); } static int vertex_group_mesh_poll(bContext *C) @@ -2471,8 +2504,8 @@ static int vertex_group_mesh_poll(bContext *C) Object *ob = ED_object_context(C); ID *data = (ob) ? ob->data : NULL; - return (ob && !ID_IS_LINKED_DATABLOCK(ob) && - data && !ID_IS_LINKED_DATABLOCK(data) && + return (ob && !ID_IS_LINKED(ob) && + data && !ID_IS_LINKED(data) && ob->type == OB_MESH && ob->defbase.first); } @@ -2481,7 +2514,7 @@ static int UNUSED_FUNCTION(vertex_group_mesh_supported_poll)(bContext *C) { Object *ob = ED_object_context(C); ID *data = (ob) ? ob->data : NULL; - return (ob && !ID_IS_LINKED_DATABLOCK(ob) && ob->type == OB_MESH && data && !ID_IS_LINKED_DATABLOCK(data)); + return (ob && !ID_IS_LINKED(ob) && ob->type == OB_MESH && data && !ID_IS_LINKED(data)); } @@ -2490,19 +2523,19 @@ static int UNUSED_FUNCTION(vertex_group_poll_edit) (bContext *C) Object *ob = ED_object_context(C); ID *data = (ob) ? ob->data : NULL; - if (!(ob && !ID_IS_LINKED_DATABLOCK(ob) && data && !ID_IS_LINKED_DATABLOCK(data))) + if (!(ob && !ID_IS_LINKED(ob) && data && !ID_IS_LINKED(data))) return 0; return BKE_object_is_in_editmode_vgroup(ob); } /* 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; - if (!(ob && !ID_IS_LINKED_DATABLOCK(ob) && data && !ID_IS_LINKED_DATABLOCK(data))) + if (!(ob && !ID_IS_LINKED(ob) && data && !ID_IS_LINKED(data))) return false; if (ob_type_flag && (((1 << ob->type) & ob_type_flag)) == 0) { @@ -2513,12 +2546,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 { @@ -2526,15 +2564,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) @@ -2542,7 +2596,7 @@ static int vertex_group_vert_select_unlocked_poll(bContext *C) Object *ob = ED_object_context(C); ID *data = (ob) ? ob->data : NULL; - if (!(ob && !ID_IS_LINKED_DATABLOCK(ob) && data && !ID_IS_LINKED_DATABLOCK(data))) + if (!(ob && !ID_IS_LINKED(ob) && data && !ID_IS_LINKED(data))) return 0; if (!(BKE_object_is_in_editmode_vgroup(ob) || @@ -2565,7 +2619,7 @@ static int vertex_group_vert_select_mesh_poll(bContext *C) Object *ob = ED_object_context(C); ID *data = (ob) ? ob->data : NULL; - if (!(ob && !ID_IS_LINKED_DATABLOCK(ob) && data && !ID_IS_LINKED_DATABLOCK(data))) + if (!(ob && !ID_IS_LINKED(ob) && data && !ID_IS_LINKED(data))) return 0; /* only difference to #vertex_group_vert_select_poll */ @@ -2757,7 +2811,7 @@ static int vertex_group_select_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = ED_object_context(C); - if (!ob || ID_IS_LINKED_DATABLOCK(ob)) + if (!ob || ID_IS_LINKED(ob)) return OPERATOR_CANCELLED; vgroup_select_verts(ob, 1); @@ -3081,13 +3135,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); @@ -3099,20 +3152,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 */ @@ -3123,7 +3169,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) @@ -3258,12 +3303,13 @@ static int vertex_group_mirror_exec(bContext *C, wmOperator *op) Object *ob = ED_object_context(C); int totmirr = 0, totfail = 0; - ED_vgroup_mirror(ob, - RNA_boolean_get(op->ptr, "mirror_weights"), - RNA_boolean_get(op->ptr, "flip_group_names"), - RNA_boolean_get(op->ptr, "all_groups"), - RNA_boolean_get(op->ptr, "use_topology"), - &totmirr, &totfail); + ED_vgroup_mirror( + ob, + RNA_boolean_get(op->ptr, "mirror_weights"), + RNA_boolean_get(op->ptr, "flip_group_names"), + RNA_boolean_get(op->ptr, "all_groups"), + RNA_boolean_get(op->ptr, "use_topology"), + &totmirr, &totfail); ED_mesh_report_mirror(op, totmirr, totfail); @@ -3397,7 +3443,7 @@ static int set_active_group_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -static EnumPropertyItem *vgroup_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free) +static const EnumPropertyItem *vgroup_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free) { Object *ob = ED_object_context(C); EnumPropertyItem tmp = {0, "", 0, "", ""}; @@ -3616,7 +3662,7 @@ static int vertex_group_sort_exec(bContext *C, wmOperator *op) void OBJECT_OT_vertex_group_sort(wmOperatorType *ot) { - static EnumPropertyItem vgroup_sort_type[] = { + static const EnumPropertyItem vgroup_sort_type[] = { {SORT_TYPE_NAME, "NAME", 0, "Name", ""}, {SORT_TYPE_BONEHIERARCHY, "BONE_HIERARCHY", 0, "Bone Hierarchy", ""}, {0, NULL, 0, NULL, NULL} @@ -3667,7 +3713,7 @@ static int vgroup_move_exec(bContext *C, wmOperator *op) void OBJECT_OT_vertex_group_move(wmOperatorType *ot) { - static EnumPropertyItem vgroup_slot_move[] = { + static const EnumPropertyItem vgroup_slot_move[] = { {-1, "UP", 0, "Up", ""}, {1, "DOWN", 0, "Down", ""}, {0, NULL, 0, NULL, NULL} |