diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-07-04 23:34:49 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-07-04 23:34:49 +0400 |
commit | cee5bd4623c4508eaa41cf498b05a54686891ce3 (patch) | |
tree | feda68cf710e4d6dbe3645dcdc44bc37c964730d /source/blender/editors/object/object_vgroup.c | |
parent | 5ad4550f2278f9688a40321998d256438c2417cc (diff) |
changes to weight paint transfer
- Use the active group of the active (target) object (not the active group of the other, unselected object)
- Ensure the active group doesnt change from the one that was set originally.
- defgroup_find_name was doing redundant lookup on its self.
Diffstat (limited to 'source/blender/editors/object/object_vgroup.c')
-rw-r--r-- | source/blender/editors/object/object_vgroup.c | 52 |
1 files changed, 40 insertions, 12 deletions
diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index bda69af3513..9c8e49e873d 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -749,10 +749,12 @@ static bool ed_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGro unsigned int f_index; float weight, tmp_weight[4], tmp_co[3], normal[3], tmp_mat[4][4], dist_v1, dist_v2, dist_v3, dist_v4; const int use_vert_sel = vertex_group_use_vert_sel(ob_dst); + bool is_dg_dst_new = false; /* Ensure vertex group on target.*/ if ((dg_dst = defgroup_find_name(ob_dst, dg_src->name)) == NULL) { dg_dst = BKE_defgroup_new(ob_dst, dg_src->name); + is_dg_dst_new = true; } /* Get meshes.*/ @@ -804,7 +806,10 @@ static bool ed_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGro if (ob_dst == ob_src || dv_tot_dst == 0 || dv_tot_dst != dv_tot_src || dv_array_src == NULL || dv_array_dst == NULL) { - ED_vgroup_delete(ob_dst, defgroup_find_name(ob_dst, dg_dst->name)); + if (is_dg_dst_new) { + ED_vgroup_delete(ob_dst, dg_dst); + } + if (dv_array_src) MEM_freeN(dv_array_src); if (dv_array_dst) MEM_freeN(dv_array_dst); dmesh_src->release(dmesh_src); @@ -901,18 +906,16 @@ static bool ed_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGro project_v3_plane(tmp_co, normal, mv_src[mf->v1].co); /* Interpolate weights over face.*/ - f_index = mf->v4 ? 3 : 2; - if (f_index == 3) { - interp_weights_face_v3(tmp_weight, mv_src[mf->v1].co, mv_src[mf->v2].co, - mv_src[mf->v3].co, mv_src[mf->v4].co, tmp_co); - } - else { - interp_weights_face_v3(tmp_weight, mv_src[mf->v1].co, mv_src[mf->v2].co, - mv_src[mf->v3].co, NULL, tmp_co); - } + interp_weights_face_v3(tmp_weight, + mv_src[mf->v1].co, + mv_src[mf->v2].co, + mv_src[mf->v3].co, + mf->v4 ? mv_src[mf->v4].co : NULL, + tmp_co); /* Get weights from face.*/ - weight = 0; + f_index = mf->v4 ? 3 : 2; + weight = 0.0f; do { v_index = (&mf->v1)[f_index]; weight += tmp_weight[f_index] * defvert_find_weight(dv_array_src[v_index], index_src); @@ -920,7 +923,7 @@ static bool ed_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGro /* Copy weight that are not NULL including weight value 0. In relevant cases, existing weights are * overwritten prior to this. See the "Clear weights." step above.*/ - if (weight > 0) { + if (weight > 0.0f) { dw_dst = defvert_verify_index(*dv_dst, index_dst); vgroup_transfer_weight(&dw_dst->weight, weight, replace_mode); } @@ -3764,6 +3767,10 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); Object *ob_act = CTX_data_active_object(C); + + bDeformGroup *dg_act = BLI_findlink(&ob_act->defbase, (ob_act->actdef - 1)); + char dg_act_name[MAX_VGROUP_NAME]; /* may be freed so copy */ + int fail = 0; bool change = false; @@ -3771,6 +3778,17 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) WT_Method method = RNA_enum_get(op->ptr, "method"); WT_ReplaceMode replace_mode = RNA_enum_get(op->ptr, "replace_mode"); + if (vertex_group_mode == WT_REPLACE_ACTIVE_VERTEX_GROUP) { + if (!dg_act) { + BKE_report(op->reports, RPT_WARNING, "Failed, active object has no active groups"); + return OPERATOR_CANCELLED; + } + } + + if (dg_act) { + BLI_strncpy(dg_act_name, dg_act->name, sizeof(dg_act_name)); + } + /* Macro to loop through selected objects and perform operation depending on function, option and method.*/ CTX_DATA_BEGIN (C, Object *, ob_src, selected_editable_objects) { @@ -3823,8 +3841,18 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) CTX_DATA_END; if (change) { + + /* possible the active vertex group changed because of adding/removing */ + /* note!, dg_act may be realloc'd, only check its not NULL */ + if (dg_act) { + ED_vgroup_select_by_name(ob_act, dg_act_name); + } + /* Event notifiers for correct display of data.*/ + + DAG_id_tag_update(&ob_act->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob_act); /* for buttons */ WM_event_add_notifier(C, NC_GEOM | ND_VERTEX_GROUP, ob_act); return OPERATOR_FINISHED; } |