Added generic function to Sync pose bone with active vgroup. For use in Weight Paint and Vertex Paint

This commit is contained in:
2013-07-04 21:49:48 +00:00
parent db9f21ddd3
commit a07a72d93d
3 changed files with 26 additions and 12 deletions

View File

@@ -233,6 +233,7 @@ void ED_mesh_mirrtopo_free(MirrTopoStore_t *mesh_topo_store);
#define WEIGHT_ADD 2
#define WEIGHT_SUBTRACT 3
bool ED_vgroup_sync_from_pose(struct Object *ob);
struct bDeformGroup *ED_vgroup_add(struct Object *ob);
struct bDeformGroup *ED_vgroup_add_name(struct Object *ob, const char *name);
void ED_vgroup_delete(struct Object *ob, struct bDeformGroup *defgroup);

View File

@@ -109,6 +109,22 @@ static Lattice *vgroup_edit_lattice(Object *ob)
return (lt->editlatt) ? lt->editlatt->latt : lt;
}
bool ED_vgroup_sync_from_pose(Object *ob)
{
Object *armobj = BKE_object_pose_armature_get(ob);
if (armobj && (armobj->mode & OB_MODE_POSE)) {
struct bArmature *arm = armobj->data;
if (arm->act_bone) {
int def_num = defgroup_name_index(ob, arm->act_bone->name);
if (def_num != -1) {
ob->actdef = def_num + 1;
return true;
}
}
}
return false;
}
bool ED_vgroup_object_is_edit_mode(Object *ob)
{
if (ob->type == OB_MESH)
@@ -3800,8 +3816,11 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op)
continue;
}
else if (ob_src->type != OB_MESH) {
BKE_reportf(op->reports, RPT_WARNING,
"Skipping object '%s' only copying from meshes is supported", ob_src->id.name + 2);
/* armatures can be in pose mode so ignore them */
if (ob_src->type != OB_ARMATURE) {
BKE_reportf(op->reports, RPT_WARNING,
"Skipping object '%s' only copying from meshes is supported", ob_src->id.name + 2);
}
continue;
}
@@ -3854,6 +3873,9 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op)
if (dg_act) {
ED_vgroup_select_by_name(ob_act, dg_act_name);
}
else {
ED_vgroup_sync_from_pose(ob_act);
}
/* Event notifiers for correct display of data.*/

View File

@@ -2047,8 +2047,6 @@ static int set_wpaint(bContext *C, wmOperator *UNUSED(op)) /* toggle */
DAG_id_tag_update(&me->id, 0);
if (ob->mode & OB_MODE_WEIGHT_PAINT) {
Object *par;
if (wp == NULL)
wp = scene->toolsettings->wpaint = new_vpaint(1);
@@ -2057,14 +2055,7 @@ static int set_wpaint(bContext *C, wmOperator *UNUSED(op)) /* toggle */
mesh_octree_table(ob, NULL, NULL, 's');
/* verify if active weight group is also active bone */
par = modifiers_isDeformedByArmature(ob);
if (par && (par->mode & OB_MODE_POSE)) {
bArmature *arm = par->data;
if (arm->act_bone)
ED_vgroup_select_by_name(ob, arm->act_bone->name);
}
ED_vgroup_sync_from_pose(ob);
}
else {
mesh_octree_table(NULL, NULL, NULL, 'e');