svn merge ^/trunk/blender -r46844:HEAD
authorOve Murberg Henriksen <sorayasilvermoon@hotmail.com>
Wed, 23 May 2012 10:56:06 +0000 (10:56 +0000)
committerOve Murberg Henriksen <sorayasilvermoon@hotmail.com>
Wed, 23 May 2012 10:56:06 +0000 (10:56 +0000)
release/scripts/startup/bl_ui/space_view3d_toolbar.py
source/blender/editors/object/object_intern.h
source/blender/editors/object/object_ops.c
source/blender/editors/object/object_vgroup.c

index a1f616cc2377604369810aeba269752c42ee8e35..454541f7069e801c2fc0b9ab7063b6bc067f15b8 100644 (file)
@@ -954,6 +954,7 @@ class VIEW3D_PT_tools_weightpaint(View3DPanel, Panel):
 
         col = layout.column()
         col.active = ob.vertex_groups.active is not None
+        col.operator("object.vertex_group_transfer_weight", text="Transfer weight")
         col.operator("object.vertex_group_normalize_all", text="Normalize All")
         col.operator("object.vertex_group_normalize", text="Normalize")
         col.operator("object.vertex_group_mirror", text="Mirror")
index 4b33c5663ba9763aff46cd7bc5d8f6f23ba156c8..6f3cca442f001798b7007fb52d6b21438f2002b3 100644 (file)
@@ -200,6 +200,7 @@ void OBJECT_OT_vertex_group_remove_from(struct wmOperatorType *ot);
 void OBJECT_OT_vertex_group_select(struct wmOperatorType *ot);
 void OBJECT_OT_vertex_group_deselect(struct wmOperatorType *ot);
 void OBJECT_OT_vertex_group_copy_to_linked(struct wmOperatorType *ot);
+void OBJECT_OT_vertex_group_transfer_weight(struct wmOperatorType *ot);
 void OBJECT_OT_vertex_group_copy_to_selected(struct wmOperatorType *ot);
 void OBJECT_OT_vertex_group_copy(struct wmOperatorType *ot);
 void OBJECT_OT_vertex_group_normalize(struct wmOperatorType *ot);
index 01f6b64170940d23caa191b6ac79842246902bc8..0c50ab5848730d181db38775cab032e508938cc2 100644 (file)
@@ -175,6 +175,7 @@ void ED_operatortypes_object(void)
        WM_operatortype_append(OBJECT_OT_vertex_group_select);
        WM_operatortype_append(OBJECT_OT_vertex_group_deselect);
        WM_operatortype_append(OBJECT_OT_vertex_group_copy_to_linked);
+       WM_operatortype_append(OBJECT_OT_vertex_group_transfer_weight);
        WM_operatortype_append(OBJECT_OT_vertex_group_copy_to_selected);
        WM_operatortype_append(OBJECT_OT_vertex_group_copy);
        WM_operatortype_append(OBJECT_OT_vertex_group_normalize);
index 0c0611d3d33e8771e80709796a2e7a49b0be1078..6dc954b88ad71b452a7d831d948a4daaff445fe8 100644 (file)
@@ -20,7 +20,7 @@
  *
  * The Original Code is: all of this file.
  *
- * Contributor(s): none yet.
+ * Contributor(s): Ove M Henriksen.
  *
  * ***** END GPL LICENSE BLOCK *****
  */
@@ -376,6 +376,321 @@ int ED_vgroup_copy_array(Object *ob, Object *ob_from)
        return 1;
 }
 
+/********************** Start transfer weight functions *********************/
+
+int ED_vgroup_transfer_weight_by_index(Object *ob_dst, Object *ob_src, short dw_replace_options, bDeformGroup *dg_src)
+{
+       MDeformVert **dv_array_src;
+       MDeformVert **dv_array_dst;
+       MDeformWeight *dw_dst, *dw_src;
+       MVert *mv_dst;
+       Mesh *me_dst;
+       int dv_tot_src, dv_tot_dst;
+       int i, index_src, index_dst;
+       bDeformGroup *dg_dst;
+
+       enum dw_options {REPLACE_ALL_WEIGHTS = 1, REPLACE_EMPTY_WEIGHTS = 2, REPLACE_SELECTED_WEIGHTS = 3} dw_options = dw_replace_options;
+
+       /*create new and overwrite vertex group on destination without data*/
+       if (!defgroup_find_name(ob_dst, dg_src->name) || dw_options == 1){
+               ED_vgroup_delete(ob_dst, defgroup_find_name(ob_dst, dg_src->name));
+               ED_vgroup_add_name(ob_dst, dg_src->name);
+       }
+
+       /*get meshes*/
+       me_dst = ob_dst->data;
+
+       /*get vertices*/
+       mv_dst = me_dst->mvert;
+
+       /*get destination deformgroup*/
+       dg_dst = defgroup_find_name(ob_dst, dg_src->name);
+
+       /*get vertex group arrays*/
+       ED_vgroup_give_parray(ob_src->data, &dv_array_src, &dv_tot_src, FALSE);
+       ED_vgroup_give_parray(ob_dst->data, &dv_array_dst, &dv_tot_dst, FALSE);
+
+       /*get indexes of vertex groups*/
+       index_src = BLI_findindex(&ob_src->defbase, dg_src);
+       index_dst = BLI_findindex(&ob_dst->defbase, dg_dst);
+
+       /*check if indices are matching, delete and return if not*/
+       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));
+               return 0;
+       }
+
+       /* loop through the vertices and copy weight*/
+       for (i = 0; i < dv_tot_dst; i++, dv_array_src++, dv_array_dst++, mv_dst++){
+               dw_src = defvert_verify_index(*dv_array_src, index_src);
+               dw_dst = defvert_verify_index(*dv_array_dst, index_dst);
+               if (dw_options == REPLACE_ALL_WEIGHTS) dw_dst->weight = dw_src->weight;
+               else if (dw_options == REPLACE_EMPTY_WEIGHTS) {if (!dw_dst->weight || dw_dst->weight == 0) dw_dst->weight = dw_src->weight;}
+               else if (dw_options == REPLACE_SELECTED_WEIGHTS) {if (mv_dst->flag & SELECT) dw_dst->weight = dw_src->weight;}
+               else return 0;
+       }
+       return 1;
+}
+
+int ED_vgroup_transfer_weight_by_nearest_vertex(Object *ob_dst, Object *ob_src, short dw_replace_options, bDeformGroup *dg_src)
+{
+       bDeformGroup *dg_dst;
+       MDeformVert **dv_array_src, **dv_array_dst;
+       MDeformWeight *dw_dst, *dw_src;
+       MVert *mv_dst;
+       Mesh *me_dst;
+       BVHTreeFromMesh tree_mesh_src;
+       BVHTreeNearest nearest;
+       DerivedMesh *dmesh_src;
+       int dv_tot_src, dv_tot_dst, i, index_dst, index_src;
+       float tmp_co[3], tmp_mat[4][4];
+
+       enum dw_options {REPLACE_ALL_WEIGHTS = 1, REPLACE_EMPTY_WEIGHTS = 2, REPLACE_SELECTED_WEIGHTS = 3} dw_options = dw_replace_options;
+
+       /*create new and overwrite vertex group on destination without data*/
+       if (!defgroup_find_name(ob_dst, dg_src->name) || dw_replace_options == 1){
+               ED_vgroup_delete(ob_dst, defgroup_find_name(ob_dst, dg_src->name));
+               ED_vgroup_add_name(ob_dst, dg_src->name);
+       }
+
+       /*get destination deformgroup*/
+       dg_dst = defgroup_find_name(ob_dst, dg_src->name);
+
+       /*get meshes*/
+       me_dst = ob_dst->data;
+       dmesh_src = ob_src->derivedDeform;
+
+       /*make node tree*/
+       bvhtree_from_mesh_verts(&tree_mesh_src, dmesh_src, 0.0, 2, 6);
+
+       /*get vertex group arrays*/
+       ED_vgroup_give_parray(ob_src->data, &dv_array_src, &dv_tot_src, FALSE);
+       ED_vgroup_give_parray(ob_dst->data, &dv_array_dst, &dv_tot_dst, FALSE);
+
+       /*get indexes of vertex groups*/
+       index_src = BLI_findindex(&ob_src->defbase, dg_src);
+       index_dst = BLI_findindex(&ob_dst->defbase, dg_dst);
+
+       /*get vertices*/
+       mv_dst = me_dst->mvert;
+
+       /*prepare transformation matrix*/
+       invert_m4_m4(ob_src->imat, ob_src->obmat);
+       mult_m4_m4m4(tmp_mat, ob_src->imat, ob_dst->obmat);
+
+       /* loop through the vertices and copy weight*/
+       for (i = 0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++){
+
+               /*reset nearest*/
+               nearest.index = -1;
+               nearest.dist = FLT_MAX;
+
+               /*transform into target space*/
+               mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co);
+
+               /*node tree accelerated search for closest vetex*/
+               BLI_bvhtree_find_nearest(tree_mesh_src.tree, tmp_co, &nearest, tree_mesh_src.nearest_callback, &tree_mesh_src);
+               dw_src = defvert_verify_index(dv_array_src[nearest.index], index_src);
+               dw_dst = defvert_verify_index(*dv_array_dst, index_dst);
+               if (dw_options == REPLACE_ALL_WEIGHTS) dw_dst->weight = dw_src->weight;
+               else if (dw_options == REPLACE_EMPTY_WEIGHTS) {if (!dw_dst->weight || dw_dst->weight == 0) dw_dst->weight = dw_src->weight;}
+               else if(dw_options ==  REPLACE_SELECTED_WEIGHTS) {if (mv_dst->flag & SELECT) dw_dst->weight = dw_src->weight;}
+               else return 0;
+       }
+
+       /*free memory and return*/
+       free_bvhtree_from_mesh(&tree_mesh_src);
+       return 1;
+}
+
+int ED_vgroup_transfer_weight_by_nearest_face(Object *ob_dst, Object *ob_src, short dw_replace_options, bDeformGroup *dg_src)
+{
+       bDeformGroup *dg_dst;
+       Mesh *me_dst;
+       DerivedMesh *dmesh_src;
+       BVHTreeFromMesh tree_mesh_faces_src = {NULL};
+       MDeformVert **dv_array_src, **dv_array_dst;
+       MVert *mv_dst, *mv_src;
+       MFace *mface_src;
+       BVHTreeNearest nearest;
+       MDeformWeight *dw_dst;
+       int dv_tot_src, dv_tot_dst, i, index_dst, index_src;
+       float weight, tmp_weight[4], tmp_co[3], normal[3], tmp_mat[4][4];
+
+       enum dw_options {REPLACE_ALL_WEIGHTS = 1, REPLACE_EMPTY_WEIGHTS = 2, REPLACE_SELECTED_WEIGHTS = 3} dw_options = dw_replace_options;
+
+       /*create new and overwrite vertex group on destination without data*/
+       if (!defgroup_find_name(ob_dst, dg_src->name) || dw_options == 1){
+               ED_vgroup_delete(ob_dst, defgroup_find_name(ob_dst, dg_src->name));
+               ED_vgroup_add_name(ob_dst, dg_src->name);
+       }
+
+       /*get destination deformgroup*/
+       dg_dst = defgroup_find_name(ob_dst, dg_src->name);
+
+       /*get meshes*/
+       me_dst = ob_dst->data;
+       dmesh_src = ob_src->derivedDeform;
+
+       /*make node tree*/
+       DM_ensure_tessface(dmesh_src);
+       bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, 0.0, 2, 6);
+
+       /*get vertex group arrays*/
+       ED_vgroup_give_parray(ob_src->data, &dv_array_src, &dv_tot_src, FALSE);
+       ED_vgroup_give_parray(ob_dst->data, &dv_array_dst, &dv_tot_dst, FALSE);
+
+       /*get indexes of vertex groups*/
+       index_src = BLI_findindex(&ob_src->defbase, dg_src);
+       index_dst = BLI_findindex(&ob_dst->defbase, dg_dst);
+
+       /*get vertices*/
+       mv_dst = me_dst->mvert;
+       mv_src = dmesh_src->getVertArray(dmesh_src);
+
+       /*get faces*/
+       mface_src = dmesh_src->getTessFaceArray(dmesh_src);
+
+       /*prepare transformation matrix*/
+       invert_m4_m4(ob_src->imat, ob_src->obmat);
+       mult_m4_m4m4(tmp_mat, ob_src->imat, ob_dst->obmat);
+
+       /* loop through the vertices and copy weight from nearest weight*/
+       for (i = 0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++){
+
+               /*reset nearest*/
+               nearest.index = -1;
+               nearest.dist = FLT_MAX;
+
+               /*transform into target space*/
+               mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co);
+               normal_tri_v3(normal, mv_src[mface_src[nearest.index].v1].co, mv_src[mface_src[nearest.index].v2].co, mv_src[mface_src[nearest.index].v3].co);
+
+               /*node tree accelerated search for closest face*/
+               BLI_bvhtree_find_nearest(tree_mesh_faces_src.tree, tmp_co, &nearest, tree_mesh_faces_src.nearest_callback, &tree_mesh_faces_src);
+
+               /*project onto face*/
+               project_v3_plane(tmp_co, normal, mv_src[mface_src[nearest.index].v1].co);
+
+               /*interpolate weights*/
+               interp_weights_face_v3(tmp_weight, mv_src[mface_src[nearest.index].v1].co,
+                                                                                                                                               mv_src[mface_src[nearest.index].v2].co,
+                                                                                                                                                       mv_src[mface_src[nearest.index].v3].co,
+                                                                                                                                                               mv_src[mface_src[nearest.index].v4].co, tmp_co);
+
+               /*get weights*/
+               weight = tmp_weight[0] * defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src)->weight;
+               weight += tmp_weight[1] * defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src)->weight;
+               weight += tmp_weight[2] * defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src)->weight;
+               weight += tmp_weight[3] * defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src)->weight;
+
+               /*copy weight*/
+               dw_dst = defvert_verify_index(*dv_array_dst, index_dst);
+               if (dw_options == REPLACE_ALL_WEIGHTS) dw_dst->weight = weight;
+               else if (dw_options == REPLACE_EMPTY_WEIGHTS) {if (!dw_dst->weight || dw_dst->weight == 0) dw_dst->weight = weight;}
+               else if (dw_options == REPLACE_SELECTED_WEIGHTS) {if (mv_dst->flag & SELECT) dw_dst->weight = weight;}
+               else return 0;
+       }
+
+       /*free memory and return*/
+       free_bvhtree_from_mesh(&tree_mesh_faces_src);
+       return 1;
+}
+
+int ED_vgroup_transfer_weight_by_nearest_vertex_in_face(Object *ob_dst, Object *ob_src, short dw_replace_options, bDeformGroup *dg_src)
+{
+       bDeformGroup *dg_dst;
+       Mesh *me_dst;
+       DerivedMesh *dmesh_src;
+       BVHTreeFromMesh tree_mesh_faces_src = {NULL};
+       MDeformVert **dv_array_src, **dv_array_dst;
+       MVert *mv_dst, *mv_src;
+       MFace *mface_src;
+       BVHTreeNearest nearest;
+       MDeformWeight *dw_dst, *dw_src;
+       int dv_tot_src, dv_tot_dst, i, index_dst, index_src, index_nearest_vertex;
+       float dist_v1, dist_v2, dist_v3, dist_v4, tmp_co[3], tmp_mat[4][4];
+
+       enum dw_options {REPLACE_ALL_WEIGHTS = 1, REPLACE_EMPTY_WEIGHTS = 2, REPLACE_SELECTED_WEIGHTS = 3} dw_options = dw_replace_options;
+
+       /*create new and overwrite vertex group on destination without data*/
+       if (!defgroup_find_name(ob_dst, dg_src->name) || dw_replace_options == 1){
+               ED_vgroup_delete(ob_dst, defgroup_find_name(ob_dst, dg_src->name));
+               ED_vgroup_add_name(ob_dst, dg_src->name);
+       }
+
+       /*get destination deformgroup*/
+       dg_dst = defgroup_find_name(ob_dst, dg_src->name);
+
+       /*get meshes*/
+       me_dst = ob_dst->data;
+       dmesh_src = ob_src->derivedDeform;
+
+       /*make node tree*/
+       DM_ensure_tessface(dmesh_src);
+       bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, 0.0, 2, 6);
+
+       /*get vertex group arrays*/
+       ED_vgroup_give_parray(ob_src->data, &dv_array_src, &dv_tot_src, FALSE);
+       ED_vgroup_give_parray(ob_dst->data, &dv_array_dst, &dv_tot_dst, FALSE);
+
+       /*get indexes of vertex groups*/
+       index_src = BLI_findindex(&ob_src->defbase, dg_src);
+       index_dst = BLI_findindex(&ob_dst->defbase, dg_dst);
+
+       /*get vertices*/
+       mv_dst = me_dst->mvert;
+       mv_src = dmesh_src->getVertArray(dmesh_src);
+
+       /*get faces*/
+       mface_src = dmesh_src->getTessFaceArray(dmesh_src);
+
+       /*prepare transformation matrix*/
+       invert_m4_m4(ob_src->imat, ob_src->obmat);
+       mult_m4_m4m4(tmp_mat, ob_src->imat, ob_dst->obmat);
+
+       /* loop through the vertices and copy weight from nearest weight*/
+       for (i = 0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++){
+
+               /*reset nearest*/
+               nearest.index = -1;
+               nearest.dist = FLT_MAX;
+
+               /*transform into target space*/
+               mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co);
+
+               /*node tree accelerated search for closest face*/
+               BLI_bvhtree_find_nearest(tree_mesh_faces_src.tree, tmp_co, &nearest, tree_mesh_faces_src.nearest_callback, &tree_mesh_faces_src);
+
+               /*get distances*/
+               dist_v1 = len_squared_v3v3(tmp_co, mv_src[mface_src[nearest.index].v1].co);
+               dist_v2 = len_squared_v3v3(tmp_co, mv_src[mface_src[nearest.index].v2].co);
+               dist_v3 = len_squared_v3v3(tmp_co, mv_src[mface_src[nearest.index].v3].co);
+
+               /*get closest vertex*/
+               if (dist_v1 < dist_v2 && dist_v1 < dist_v3) index_nearest_vertex = mface_src[nearest.index].v1;
+               else if (dist_v2 < dist_v3) index_nearest_vertex = mface_src[nearest.index].v2;
+               else index_nearest_vertex = mface_src[nearest.index].v3;
+               if (mface_src[nearest.index].v4){
+                       dist_v4 = len_squared_v3v3(tmp_co, mv_src[mface_src[nearest.index].v4].co);
+                       if (dist_v4 < dist_v1 && dist_v4 < dist_v2 && dist_v4 < dist_v3) index_nearest_vertex = mface_src[nearest.index].v4;
+               }
+
+               /*copy weight*/
+               dw_src = defvert_verify_index(dv_array_src[index_nearest_vertex], index_src);
+               dw_dst = defvert_verify_index(*dv_array_dst, index_dst);
+               if (dw_options == REPLACE_ALL_WEIGHTS) dw_dst->weight = dw_src->weight;
+               else if (dw_options == REPLACE_EMPTY_WEIGHTS) {if (!dw_dst->weight || dw_dst->weight == 0) dw_dst->weight = dw_src->weight;}
+               else if (dw_options == REPLACE_SELECTED_WEIGHTS) {if (mv_dst->flag & SELECT) dw_dst->weight = dw_src->weight;}
+               else return 0;
+       }
+
+       /*free memory and return*/
+       free_bvhtree_from_mesh(&tree_mesh_faces_src);
+       return 1;
+}
+
+/********************** End transfer weight functions *********************/
 
 /* for Mesh in Object mode */
 /* allows editmode for Lattice */
@@ -2744,7 +3059,6 @@ static int vertex_group_copy_to_selected_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-
 void OBJECT_OT_vertex_group_copy_to_selected(wmOperatorType *ot)
 {
        /* identifiers */
@@ -2760,6 +3074,100 @@ void OBJECT_OT_vertex_group_copy_to_selected(wmOperatorType *ot)
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
+static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op)
+{
+       Object *ob_act = CTX_data_active_object(C);
+       int change = 0;
+       int fail = 0;
+       short dw_replace_options;
+       bDeformGroup *dg_src;
+
+       /*TODO: get these parameters*/
+       enum dg_options {REPLACE_SINGLE_VERTEX_GROUP = 1, REPLACE_ALL_VERTEX_GROUPS = 2} dg_options = 2;
+       enum function_options {BY_INDEX = 1, BY_NEAREST_VERTEX = 2, BY_NEAREST_FACE = 3, BY_NEAREST_VERTEX_IN_FACE = 4} function_options = 4;
+       dw_replace_options = 1; /*REPLACE_ALL_WEIGHTS = 1, REPLACE_EMPTY_WEIGHTS = 2, REPLACE_SELECTED_WEIGHTS = 3*/
+
+       /*Macro to loop through selected objects and perform operation depending on function, option and method*/
+       CTX_DATA_BEGIN(C, Object*, ob_slc, selected_editable_objects){
+               if (ob_act != ob_slc){
+                       switch(dg_options){
+
+                               case(REPLACE_SINGLE_VERTEX_GROUP):
+                                       dg_src = BLI_findlink(&ob_act->defbase, ob_act->actdef -1);
+                                       switch(function_options){
+
+                                               case(BY_INDEX):
+                                                       if (ED_vgroup_transfer_weight_by_index(ob_slc, ob_act, dw_replace_options, dg_src)) change++;
+                                                       else fail++; break;
+
+                                               case(BY_NEAREST_VERTEX):
+                                                       if (ED_vgroup_transfer_weight_by_nearest_vertex(ob_slc, ob_act, dw_replace_options, dg_src)) change++;
+                                                       else fail++; break;
+
+                                               case(BY_NEAREST_FACE):
+                                                       if (ED_vgroup_transfer_weight_by_nearest_face(ob_slc, ob_act, dw_replace_options, dg_src)) change++;
+                                                       else fail++; break;
+
+                                               case(BY_NEAREST_VERTEX_IN_FACE):
+                                                       if (ED_vgroup_transfer_weight_by_nearest_vertex_in_face(ob_slc, ob_act, dw_replace_options, dg_src)) change++;
+                                                       else fail++; break;
+                                       }
+
+                               case(REPLACE_ALL_VERTEX_GROUPS):
+                                       for (dg_src = ob_act->defbase.first; dg_src; dg_src = dg_src->next){
+                                               switch(function_options){
+
+                                                       case(BY_INDEX):
+                                                               if (ED_vgroup_transfer_weight_by_index(ob_slc, ob_act, dw_replace_options, dg_src)) change++;
+                                                               else fail++; break;
+
+                                                       case(BY_NEAREST_VERTEX):
+                                                               if (ED_vgroup_transfer_weight_by_nearest_vertex(ob_slc, ob_act, dw_replace_options, dg_src)) change++;
+                                                               else fail++; break;
+
+                                                       case(BY_NEAREST_FACE):
+                                                               if (ED_vgroup_transfer_weight_by_nearest_face(ob_slc, ob_act, dw_replace_options, dg_src)) change++;
+                                                               else fail++; break;
+
+                                                       case(BY_NEAREST_VERTEX_IN_FACE):
+                                                               if (ED_vgroup_transfer_weight_by_nearest_vertex_in_face(ob_slc, ob_act, dw_replace_options, dg_src)) change++;
+                                                               else fail++; break;
+                                               }
+                                       }
+                               }
+                       }
+               /*Event notifiers for correct display of data*/
+               DAG_id_tag_update(&ob_slc->id, OB_RECALC_DATA);
+               WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob_slc);
+               WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob_slc->data);
+       }
+       CTX_DATA_END;
+
+       /*Report error when task can not be completed with available functions.*/
+       if ((change == 0 && fail == 0) || fail) {
+               BKE_reportf(op->reports, RPT_ERROR,
+                           "Copy to VGroups to Selected warning done %d, failed %d, unknown option/method or All functions failed!",
+                           change, fail);
+       }
+       return OPERATOR_FINISHED;
+}
+
+/*transfers weight from active to selected*/
+void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Transfer weight to selected";
+       ot->idname = "OBJECT_OT_vertex_group_transfer_weight";
+       ot->description = "Transfers weight from active to selected depending on options";
+
+       /* api callbacks */
+       ot->poll = vertex_group_poll;
+       ot->exec = vertex_group_transfer_weight_exec;
+
+       /* flags */
+       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
 static EnumPropertyItem vgroup_items[] = {
        {0, NULL, 0, NULL, NULL}
 };