svn merge ^/trunk/blender -r46000:46100
authorOve Murberg Henriksen <sorayasilvermoon@hotmail.com>
Sun, 6 May 2012 22:19:13 +0000 (22:19 +0000)
committerOve Murberg Henriksen <sorayasilvermoon@hotmail.com>
Sun, 6 May 2012 22:19:13 +0000 (22:19 +0000)
some conflicts. had to backup my code, accept with "tc" and introduce my own code again.
Hope I didnt leave anything out.

1  2 
source/blender/editors/object/object_intern.h
source/blender/editors/object/object_ops.c
source/blender/editors/object/object_vgroup.c

index 8ba64e66025dacdcee644d2d833c498d954d6580,ee9d776ea3b7b266b25de32b9198d3f23acef496..28de0b4b33f79cecc0495e2e0a7c7fbe1cddd92f
@@@ -185,7 -185,7 +185,7 @@@ void CONSTRAINT_OT_limitdistance_reset(
  void CONSTRAINT_OT_childof_set_inverse(struct wmOperatorType *ot);
  void CONSTRAINT_OT_childof_clear_inverse(struct wmOperatorType *ot);
  void CONSTRAINT_OT_objectsolver_set_inverse(struct wmOperatorType *ot);
- void CONSTRAINT_OT_objectsolver_clear_inverse (struct wmOperatorType *ot);
+ void CONSTRAINT_OT_objectsolver_clear_inverse(struct wmOperatorType *ot);
  
  /* object_vgroup.c */
  void OBJECT_OT_vertex_group_add(struct wmOperatorType *ot);
@@@ -196,7 -196,6 +196,7 @@@ void OBJECT_OT_vertex_group_select(stru
  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_copy_to_selected(struct wmOperatorType *ot);
 +void OBJECT_OT_vertex_group_copy_to_selected_single(struct wmOperatorType *ot);
  void OBJECT_OT_vertex_group_copy(struct wmOperatorType *ot);
  void OBJECT_OT_vertex_group_normalize(struct wmOperatorType *ot);
  void OBJECT_OT_vertex_group_normalize_all(struct wmOperatorType *ot);
index 43385ea80a314771acc09d5331546b3d06f97b06,4cd18d912499c9db282d6306ca08b5a402f78872..72f2317794633f1ab2df796a16d2e6f82aa7eb70
@@@ -170,7 -170,6 +170,7 @@@ void ED_operatortypes_object(void
        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_copy_to_selected);
 +      WM_operatortype_append(OBJECT_OT_vertex_group_copy_to_selected_single);
        WM_operatortype_append(OBJECT_OT_vertex_group_copy);
        WM_operatortype_append(OBJECT_OT_vertex_group_normalize);
        WM_operatortype_append(OBJECT_OT_vertex_group_normalize_all);
@@@ -223,7 -222,7 +223,7 @@@ void ED_operatormacros_object(void
        wmOperatorType *ot;
        wmOperatorTypeMacro *otmacro;
        
-       ot = WM_operatortype_append_macro("OBJECT_OT_duplicate_move", "Duplicate Objects", OPTYPE_UNDO|OPTYPE_REGISTER);
+       ot = WM_operatortype_append_macro("OBJECT_OT_duplicate_move", "Duplicate Objects", OPTYPE_UNDO | OPTYPE_REGISTER);
        if (ot) {
                ot->description = "Duplicate selected objects and move them";
                WM_operatortype_macro_define(ot, "OBJECT_OT_duplicate");
        }
  
        /* grr, should be able to pass options on... */
-       ot = WM_operatortype_append_macro("OBJECT_OT_duplicate_move_linked", "Duplicate Linked", OPTYPE_UNDO|OPTYPE_REGISTER);
+       ot = WM_operatortype_append_macro("OBJECT_OT_duplicate_move_linked", "Duplicate Linked", OPTYPE_UNDO | OPTYPE_REGISTER);
        if (ot) {
                ot->description = "Duplicate selected objects and move them";
                otmacro = WM_operatortype_macro_define(ot, "OBJECT_OT_duplicate");
        }
        
        /* XXX */
-       ot = WM_operatortype_append_macro("OBJECT_OT_add_named_cursor", "Add named object at cursor", OPTYPE_UNDO|OPTYPE_REGISTER);
+       ot = WM_operatortype_append_macro("OBJECT_OT_add_named_cursor", "Add named object at cursor", OPTYPE_UNDO | OPTYPE_REGISTER);
        if (ot) {
                ot->description = "Add named object at cursor";
-               RNA_def_string(ot->srna, "name", "Cube", MAX_ID_NAME-2, "Name", "Object name to add");
+               RNA_def_string(ot->srna, "name", "Cube", MAX_ID_NAME - 2, "Name", "Object name to add");
  
                WM_operatortype_macro_define(ot, "VIEW3D_OT_cursor3d");
                WM_operatortype_macro_define(ot, "OBJECT_OT_add_named");
  
  static int object_mode_poll(bContext *C)
  {
-       Object *ob= CTX_data_active_object(C);
+       Object *ob = CTX_data_active_object(C);
        return (!ob || ob->mode == OB_MODE_OBJECT);
  }
  
@@@ -284,7 -283,7 +284,7 @@@ void ED_keymap_object(wmKeyConfig *keyc
        RNA_enum_set(kmi->ptr, "mode", OB_MODE_WEIGHT_PAINT);
        RNA_boolean_set(kmi->ptr, "toggle", TRUE);
        
-       WM_keymap_add_item(keymap, "OBJECT_OT_origin_set", CKEY, KM_PRESS, KM_ALT|KM_SHIFT|KM_CTRL, 0);
+       WM_keymap_add_item(keymap, "OBJECT_OT_origin_set", CKEY, KM_PRESS, KM_ALT | KM_SHIFT | KM_CTRL, 0);
  
        /* Object Mode ---------------------------------------------------------------- */
        /* Note: this keymap gets disabled in non-objectmode,  */
  
        WM_keymap_add_item(keymap, "OBJECT_OT_select_linked", LKEY, KM_PRESS, KM_SHIFT, 0);
        WM_keymap_add_item(keymap, "OBJECT_OT_select_grouped", GKEY, KM_PRESS, KM_SHIFT, 0);
-       WM_keymap_add_item(keymap, "OBJECT_OT_select_mirror", MKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
+       WM_keymap_add_item(keymap, "OBJECT_OT_select_mirror", MKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
        
        kmi = WM_keymap_add_item(keymap, "OBJECT_OT_select_hierarchy", LEFTBRACKETKEY, KM_PRESS, 0, 0);
        RNA_enum_set_identifier(kmi->ptr, "direction", "PARENT");
        RNA_boolean_set(kmi->ptr, "extend", TRUE);
  
        WM_keymap_verify_item(keymap, "OBJECT_OT_parent_set", PKEY, KM_PRESS, KM_CTRL, 0);
-       WM_keymap_verify_item(keymap, "OBJECT_OT_parent_no_inverse_set", PKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
+       WM_keymap_verify_item(keymap, "OBJECT_OT_parent_no_inverse_set", PKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
        WM_keymap_verify_item(keymap, "OBJECT_OT_parent_clear", PKEY, KM_PRESS, KM_ALT, 0);
        WM_keymap_verify_item(keymap, "OBJECT_OT_track_set", TKEY, KM_PRESS, KM_CTRL, 0);
        WM_keymap_verify_item(keymap, "OBJECT_OT_track_clear", TKEY, KM_PRESS, KM_ALT, 0);
        
-       WM_keymap_verify_item(keymap, "OBJECT_OT_constraint_add_with_targets", CKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
-       WM_keymap_verify_item(keymap, "OBJECT_OT_constraints_clear", CKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
+       WM_keymap_verify_item(keymap, "OBJECT_OT_constraint_add_with_targets", CKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
+       WM_keymap_verify_item(keymap, "OBJECT_OT_constraints_clear", CKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
        
        WM_keymap_verify_item(keymap, "OBJECT_OT_location_clear", GKEY, KM_PRESS, KM_ALT, 0);
        WM_keymap_verify_item(keymap, "OBJECT_OT_rotation_clear", RKEY, KM_PRESS, KM_ALT, 0);
        RNA_boolean_set(kmi->ptr, "unselected", TRUE);
  
        /* same as above but for rendering */
-       WM_keymap_add_item(keymap, "OBJECT_OT_hide_render_clear", HKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
+       WM_keymap_add_item(keymap, "OBJECT_OT_hide_render_clear", HKEY, KM_PRESS, KM_ALT | KM_CTRL, 0);
        WM_keymap_add_item(keymap, "OBJECT_OT_hide_render_set", HKEY, KM_PRESS, KM_CTRL, 0);
  
        /* conflicts, removing */
  #if 0
-       kmi = WM_keymap_add_item(keymap, "OBJECT_OT_hide_render_set", HKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)
-       RNA_boolean_set(kmi->ptr, "unselected", TRUE);
+       kmi = WM_keymap_add_item(keymap, "OBJECT_OT_hide_render_set", HKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0)
+             RNA_boolean_set(kmi->ptr, "unselected", TRUE);
  #endif
  
        WM_keymap_add_item(keymap, "OBJECT_OT_move_to_layer", MKEY, KM_PRESS, 0, 0);
  
        WM_keymap_add_menu(keymap, "INFO_MT_add", AKEY, KM_PRESS, KM_SHIFT, 0);
  
-       WM_keymap_add_item(keymap, "OBJECT_OT_duplicates_make_real", AKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
+       WM_keymap_add_item(keymap, "OBJECT_OT_duplicates_make_real", AKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
  
        WM_keymap_add_menu(keymap, "VIEW3D_MT_object_apply", AKEY, KM_PRESS, KM_CTRL, 0);
        WM_keymap_add_menu(keymap, "VIEW3D_MT_make_single_user", UKEY, KM_PRESS, 0, 0);
        
        WM_keymap_add_item(keymap, "OBJECT_OT_join", JKEY, KM_PRESS, KM_CTRL, 0);
        WM_keymap_add_item(keymap, "OBJECT_OT_convert", CKEY, KM_PRESS, KM_ALT, 0);
-       WM_keymap_add_item(keymap, "OBJECT_OT_proxy_make", PKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
+       WM_keymap_add_item(keymap, "OBJECT_OT_proxy_make", PKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
        WM_keymap_add_item(keymap, "OBJECT_OT_make_local", LKEY, KM_PRESS, 0, 0);
  
        // XXX this should probably be in screen instead... here for testing purposes in the meantime... - Aligorith
        WM_keymap_verify_item(keymap, "ANIM_OT_keyframe_insert_menu", IKEY, KM_PRESS, 0, 0);
        WM_keymap_verify_item(keymap, "ANIM_OT_keyframe_delete_v3d", IKEY, KM_PRESS, KM_ALT, 0);
-       WM_keymap_verify_item(keymap, "ANIM_OT_keying_set_active_set", IKEY, KM_PRESS, KM_CTRL|KM_SHIFT|KM_ALT, 0);
+       WM_keymap_verify_item(keymap, "ANIM_OT_keying_set_active_set", IKEY, KM_PRESS, KM_CTRL | KM_SHIFT | KM_ALT, 0);
        
        WM_keymap_verify_item(keymap, "GROUP_OT_create", GKEY, KM_PRESS, KM_CTRL, 0);
-       WM_keymap_verify_item(keymap, "GROUP_OT_objects_remove", GKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
-       WM_keymap_verify_item(keymap, "GROUP_OT_objects_add_active", GKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
-       WM_keymap_verify_item(keymap, "GROUP_OT_objects_remove_active", GKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0);
+       WM_keymap_verify_item(keymap, "GROUP_OT_objects_remove", GKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
+       WM_keymap_verify_item(keymap, "GROUP_OT_objects_add_active", GKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
+       WM_keymap_verify_item(keymap, "GROUP_OT_objects_remove_active", GKEY, KM_PRESS, KM_SHIFT | KM_ALT, 0);
  
        WM_keymap_add_menu(keymap, "VIEW3D_MT_object_specials", WKEY, KM_PRESS, 0, 0);
  
-       for (i=0; i<=5; i++) {
-               kmi = WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", ZEROKEY+i, KM_PRESS, KM_CTRL, 0);
+       for (i = 0; i <= 5; i++) {
+               kmi = WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", ZEROKEY + i, KM_PRESS, KM_CTRL, 0);
                RNA_int_set(kmi->ptr, "level", i);
        }
  
index ea0b7542886f41f1214ef1a115bedf41ab49574f,6443f45ebf01540e1f4bf42d1577fe300e4d2e25..744f8adb59ff5ce997c6c6c11fe45ac875ae7bcc
@@@ -20,7 -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 *****
   */
@@@ -75,7 -75,6 +75,7 @@@
  #include "UI_resources.h"
  
  #include "object_intern.h"
 +#include <stdio.h> /*only for development purposes, remove*/
  
  /************************ Exported Functions **********************/
  static void vgroup_remap_update_users(Object *ob, int *map);
@@@ -85,9 -84,9 +85,9 @@@ static void vgroup_delete_all(Object *o
  
  static Lattice *vgroup_edit_lattice(Object *ob)
  {
-       Lattice *lt= ob->data;
-       BLI_assert(ob->type==OB_LATTICE);
-       return (lt->editlatt)? lt->editlatt->latt: lt;
+       Lattice *lt = ob->data;
+       BLI_assert(ob->type == OB_LATTICE);
+       return (lt->editlatt) ? lt->editlatt->latt : lt;
  }
  
  int ED_vgroup_object_is_edit_mode(Object *ob)
@@@ -95,7 -94,7 +95,7 @@@
        if (ob->type == OB_MESH)
                return (BMEdit_FromObject(ob) != NULL);
        else if (ob->type == OB_LATTICE)
-               return (((Lattice*)ob->data)->editlatt != NULL);
+               return (((Lattice *)ob->data)->editlatt != NULL);
  
        return 0;
  }
@@@ -145,18 -144,18 +145,18 @@@ void ED_vgroup_delete(Object *ob, bDefo
  
  void ED_vgroup_clear(Object *ob)
  {
-       bDeformGroup *dg= (bDeformGroup *)ob->defbase.first;
-       int edit_mode= ED_vgroup_object_is_edit_mode(ob);
+       bDeformGroup *dg = (bDeformGroup *)ob->defbase.first;
+       int edit_mode = ED_vgroup_object_is_edit_mode(ob);
  
        while (dg) {
-               bDeformGroup *next_dg= dg->next;
+               bDeformGroup *next_dg = dg->next;
  
                if (edit_mode)
                        vgroup_delete_edit_mode(ob, dg);
                else
                        vgroup_delete_object_mode(ob, dg);
  
-               dg= next_dg;
+               dg = next_dg;
        }
  }
  
@@@ -164,14 -163,14 +164,14 @@@ int ED_vgroup_data_create(ID *id
  {
        /* create deform verts */
  
-       if (GS(id->name)==ID_ME) {
-               Mesh *me= (Mesh *)id;
-               me->dvert= CustomData_add_layer(&me->vdata, CD_MDEFORMVERT, CD_CALLOC, NULL, me->totvert);
+       if (GS(id->name) == ID_ME) {
+               Mesh *me = (Mesh *)id;
+               me->dvert = CustomData_add_layer(&me->vdata, CD_MDEFORMVERT, CD_CALLOC, NULL, me->totvert);
                return TRUE;
        }
-       else if (GS(id->name)==ID_LT) {
-               Lattice *lt= (Lattice *)id;
-               lt->dvert= MEM_callocN(sizeof(MDeformVert)*lt->pntsu*lt->pntsv*lt->pntsw, "lattice deformVert");
+       else if (GS(id->name) == ID_LT) {
+               Lattice *lt = (Lattice *)id;
+               lt->dvert = MEM_callocN(sizeof(MDeformVert) * lt->pntsu * lt->pntsv * lt->pntsw, "lattice deformVert");
                return TRUE;
        }
        else {
@@@ -185,7 -184,7 +185,7 @@@ static int ED_vgroup_give_parray(ID *id
        *dvert_arr = NULL;
  
        if (id) {
-               switch(GS(id->name)) {
+               switch (GS(id->name)) {
                        case ID_ME:
                        {
                                Mesh *me = (Mesh *)id;
  
                                        i = em->bm->totvert;
  
-                                       *dvert_arr= MEM_mallocN(sizeof(void*)*i, "vgroup parray from me");
+                                       *dvert_arr = MEM_mallocN(sizeof(void *) * i, "vgroup parray from me");
                                        *dvert_tot = i;
  
                                        i = 0;
                                        return 1;
                                }
                                else if (me->dvert) {
-                                       MVert *mvert= me->mvert;
-                                       MDeformVert *dvert= me->dvert;
+                                       MVert *mvert = me->mvert;
+                                       MDeformVert *dvert = me->dvert;
                                        int i;
  
-                                       *dvert_tot= me->totvert;
-                                       *dvert_arr= MEM_mallocN(sizeof(void*)*me->totvert, "vgroup parray from me");
+                                       *dvert_tot = me->totvert;
+                                       *dvert_arr = MEM_mallocN(sizeof(void *) * me->totvert, "vgroup parray from me");
  
                                        if (use_vert_sel) {
-                                               for (i=0; i<me->totvert; i++) {
+                                               for (i = 0; i < me->totvert; i++) {
                                                        (*dvert_arr)[i] = (mvert[i].flag & SELECT) ?
-                                                                          &dvert[i] : NULL;
+                                                                         &dvert[i] : NULL;
                                                }
                                        }
                                        else {
-                                               for (i=0; i<me->totvert; i++) {
+                                               for (i = 0; i < me->totvert; i++) {
                                                        (*dvert_arr)[i] = me->dvert + i;
                                                }
                                        }
                        }
                        case ID_LT:
                        {
-                               int i=0;
+                               int i = 0;
  
-                               Lattice *lt= (Lattice *)id;
-                               lt= (lt->editlatt)? lt->editlatt->latt: lt;
+                               Lattice *lt = (Lattice *)id;
+                               lt = (lt->editlatt) ? lt->editlatt->latt : lt;
  
                                if (lt->dvert) {
-                                       BPoint *def= lt->def;
-                                       *dvert_tot= lt->pntsu*lt->pntsv*lt->pntsw;
-                                       *dvert_arr= MEM_mallocN(sizeof(void*)*(*dvert_tot), "vgroup parray from me");
+                                       BPoint *def = lt->def;
+                                       *dvert_tot = lt->pntsu * lt->pntsv * lt->pntsw;
+                                       *dvert_arr = MEM_mallocN(sizeof(void *) * (*dvert_tot), "vgroup parray from me");
  
                                        if (use_vert_sel) {
-                                               for (i=0; i<*dvert_tot; i++) {
+                                               for (i = 0; i < *dvert_tot; i++) {
                                                        (*dvert_arr)[i] = (def->f1 & SELECT) ?
                                                                           &lt->dvert[i] : NULL;
                                                }
                                        }
                                        else {
-                                               for (i=0; i<*dvert_tot; i++) {
+                                               for (i = 0; i < *dvert_tot; i++) {
                                                        (*dvert_arr)[i] = lt->dvert + i;
                                                }
                                        }
  int ED_vgroup_give_array(ID *id, MDeformVert **dvert_arr, int *dvert_tot)
  {
        if (id) {
-               switch(GS(id->name)) {
+               switch (GS(id->name)) {
                        case ID_ME:
                        {
                                Mesh *me = (Mesh *)id;
-                               *dvert_arr= me->dvert;
-                               *dvert_tot= me->totvert;
+                               *dvert_arr = me->dvert;
+                               *dvert_tot = me->totvert;
                                return TRUE;
                        }
                        case ID_LT:
                        {
-                               Lattice *lt= (Lattice *)id;
-                               lt= (lt->editlatt)? lt->editlatt->latt: lt;
-                               *dvert_arr= lt->dvert;
-                               *dvert_tot= lt->pntsu*lt->pntsv*lt->pntsw;
+                               Lattice *lt = (Lattice *)id;
+                               lt = (lt->editlatt) ? lt->editlatt->latt : lt;
+                               *dvert_arr = lt->dvert;
+                               *dvert_tot = lt->pntsu * lt->pntsv * lt->pntsw;
                                return TRUE;
                        }
                }
        }
  
-       *dvert_arr= NULL;
-       *dvert_tot= 0;
+       *dvert_arr = NULL;
+       *dvert_tot = 0;
        return FALSE;
  }
  
 -/* matching index only */
 +/*Copy all vertex groups to target, overwriting existing. matching index only*/
  int ED_vgroup_copy_array(Object *ob, Object *ob_from)
  {
        MDeformVert **dvert_array_from, **dvf;
        MDeformVert **dvert_array, **dv;
 -      int dvert_tot_from;
 -      int dvert_tot;
 -      int i;
 +      int dvert_tot_from, dvert_tot, i;
-       int defbase_tot_from= BLI_countlist(&ob_from->defbase);
-       int defbase_tot= BLI_countlist(&ob->defbase);
-       short new_vgroup= FALSE;
+       int defbase_tot_from = BLI_countlist(&ob_from->defbase);
+       int defbase_tot = BLI_countlist(&ob->defbase);
+       short new_vgroup = FALSE;
  
 +      /*get vertex groups arrays*/
        ED_vgroup_give_parray(ob_from->data, &dvert_array_from, &dvert_tot_from, FALSE);
        ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot, FALSE);
  
        if ((dvert_array == NULL) && (dvert_array_from != NULL) && ED_vgroup_data_create(ob->data)) {
                ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot, FALSE);
-               new_vgroup= TRUE;
+               new_vgroup = TRUE;
        }
  
-       if (ob==ob_from || dvert_tot==0 || (dvert_tot != dvert_tot_from) || dvert_array_from==NULL || dvert_array==NULL) {
+       if (ob == ob_from || dvert_tot == 0 || (dvert_tot != dvert_tot_from) || dvert_array_from == NULL || dvert_array == NULL) {
                if (dvert_array) MEM_freeN(dvert_array);
                if (dvert_array_from) MEM_freeN(dvert_array_from);
  
        /* do the copy */
        BLI_freelistN(&ob->defbase);
        BLI_duplicatelist(&ob->defbase, &ob_from->defbase);
-       ob->actdef= ob_from->actdef;
+       ob->actdef = ob_from->actdef;
  
        if (defbase_tot_from < defbase_tot) {
                /* correct vgroup indices because the number of vgroups is being reduced. */
-               int *remap= MEM_mallocN(sizeof(int) * (defbase_tot + 1), __func__);
-               for (i=0; i <= defbase_tot_from; i++) remap[i]= i;
-               for (; i <= defbase_tot; i++) remap[i]= 0; /* can't use these, so disable */
+               int *remap = MEM_mallocN(sizeof(int) * (defbase_tot + 1), __func__);
+               for (i = 0; i <= defbase_tot_from; i++) remap[i] = i;
+               for (; i <= defbase_tot; i++) remap[i] = 0;  /* can't use these, so disable */
  
                vgroup_remap_update_users(ob, remap);
                MEM_freeN(remap);
        }
  
-       dvf= dvert_array_from;
-       dv= dvert_array;
+       dvf = dvert_array_from;
+       dv = dvert_array;
  
-       for (i=0; i<dvert_tot; i++, dvf++, dv++) {
+       for (i = 0; i < dvert_tot; i++, dvf++, dv++) {
                if ((*dv)->dw)
                        MEM_freeN((*dv)->dw);
  
-               *(*dv)= *(*dvf);
+               *(*dv) = *(*dvf);
  
                if ((*dv)->dw)
-                       (*dv)->dw= MEM_dupallocN((*dv)->dw);
+                       (*dv)->dw = MEM_dupallocN((*dv)->dw);
        }
  
        MEM_freeN(dvert_array);
        return 1;
  }
  
 +/*Copy a single vertex group from source to destination with weights*/
 +int ED_vgroup_copy_single(Object *ob_dst, const Object *ob_src)
 +{
 +      MDeformVert **dv_array_src;
 +      MDeformVert **dv_array_dst;
 +      MDeformWeight *dw_dst, *dw_src;
 +      int dv_tot_src, dv_tot_dst;
 +      int i, index_src, index_dst;
 +      bDeformGroup *dg_src, *dg_dst;
 +
 +      /*get source deform group*/
 +      dg_src= BLI_findlink(&ob_src->defbase, (ob_src->actdef-1));
 +
 +      /*Create new and overwrite vertex group on destination without data*/
 +      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 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++) {
 +              dw_src= defvert_verify_index(*dv_array_src, index_src);
 +              dw_dst= defvert_verify_index(*dv_array_dst, index_dst);
 +              dw_dst->weight= dw_src->weight;
 +      }
 +
 +      return 1;
 +}
 +
 +/*Copy a single vertex group from source to destination with weights by nearest weight*/
 +int ED_vgroup_copy_by_nearest_vertex_single(Object *ob_dst, Object *ob_src)
 +{
 +      bDeformGroup *dg_src, *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];
 +
 +      /*get source deform group*/
 +      dg_src= BLI_findlink(&ob_src->defbase, (ob_src->actdef-1));
 +
 +      /*Create new and overwrite vertex group on destination without data*/
 +      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;
 +
 +      /*Prepearing transformation matrix*/
 +      /*This can be excluded to make a lazy feature that works better when object centers relative to mesh is the same*/
 +      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;
 +
 +              /*Transforming 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);
 +
 +              /*copy weight*/
 +              dw_src= defvert_verify_index(dv_array_src[nearest.index], index_src);
 +              dw_dst= defvert_verify_index(*dv_array_dst, index_dst);
 +              dw_dst->weight= dw_src->weight;
 +      }
 +
 +      /*free memory and return*/
 +      free_bvhtree_from_mesh(&tree_mesh_src);
 +      return 1;
 +}
 +
 +/*Copy a single vertex group from source to destination with weights by nearest weight*/
 +/*TODO: transform into target space as in by_vertex function. postphoned due to easier testing during development*/
 +int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src)
 +{
 +      bDeformGroup *dg_src, *dg_dst;
 +      MDeformVert **dv_array_src, **dv_array_dst;
 +      MDeformWeight *dw_dst, *dw_src;
 +      MVert *mv_dst;
 +      MFace *mface_src;
 +      Mesh *me_dst, *me_src;
 +      BVHTreeFromMesh tree_mesh_faces_src;
 +      BVHTreeNearest nearest;
 +      DerivedMesh *dmesh_src;
 +      int dv_tot_src, dv_tot_dst, i, index_dst, index_src;
 +      float weight/*, tot_dist*/;
 +
 +      /*get source deform group*/
 +      dg_src= BLI_findlink(&ob_src->defbase, (ob_src->actdef-1));
 +
 +      /*Create new and overwrite vertex group on destination without data*/
 +      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;
 +      me_src= ob_src->data;
 +      dmesh_src= ob_src->derivedDeform; /*sergey- : this might easily be null?? (using 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;
 +
 +      /* 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;
 +
 +              /*Node tree accelerated search for closest face*/
 +              BLI_bvhtree_find_nearest(tree_mesh_faces_src.tree, mv_dst->co, &nearest, tree_mesh_faces_src.nearest_callback, &tree_mesh_faces_src);
 +
 +              /*get weight*/
 +              mface_src= me_src->mface + nearest.index;
 +              /*tot_dist= ()+()+(); use a comparable distance
 +              if(mface_src->v4){
 +                      tot_dist+= ();
 +              }*/
 +              dw_src= defvert_verify_index(dv_array_src[mface_src->v1], index_src);
 +              weight= dw_src->weight;
 +              dw_src= defvert_verify_index(dv_array_src[mface_src->v2], index_src);
 +              weight+= dw_src->weight;
 +              dw_src= defvert_verify_index(dv_array_src[mface_src->v3], index_src);
 +              weight+= dw_src->weight;
 +              if(mface_src->v4){
 +                      dw_src= defvert_verify_index(dv_array_src[mface_src->v4], index_src);
 +                      weight+= dw_src->weight;
 +                      weight/=4;
 +              }
 +              else{
 +                      weight/=3;
 +              }
 +
 +
 +              /*copy weight*/
 +              dw_dst= defvert_verify_index(*dv_array_dst, index_dst);
 +              dw_dst->weight= weight;
 +      }
 +
 +      /*free memory and return*/
 +      free_bvhtree_from_mesh(&tree_mesh_faces_src);
 +      return 1;
 +}
  
  /* for Mesh in Object mode */
  /* allows editmode for Lattice */
@@@ -589,13 -386,13 +589,13 @@@ static void ED_vgroup_nr_vert_add(Objec
        /* add the vert to the deform group with the
         * specified number
         */
-       MDeformVert *dvert= NULL;
-       int     tot;
+       MDeformVert *dvert = NULL;
+       int tot;
  
        /* get the vert */
        ED_vgroup_give_array(ob->data, &dvert, &tot);
        
-       if (dvert==NULL)
+       if (dvert == NULL)
                return;
  
        /* check that vertnum is valid before trying to get the relevant dvert */
  
  
        if (dvert) {
-               MDeformVert *dv= &dvert[vertnum];
+               MDeformVert *dv = &dvert[vertnum];
                MDeformWeight *dw;
  
                /* Lets first check to see if this vert is
                 * lets update it
                 */
  
-               dw= defvert_find_index(dv, def_nr);
+               dw = defvert_find_index(dv, def_nr);
  
                if (dw) {
-                       switch(assignmode) {
-                       case WEIGHT_REPLACE:
-                               dw->weight = weight;
-                               break;
-                       case WEIGHT_ADD:
-                               dw->weight += weight;
-                               if (dw->weight >= 1.0f)
-                                       dw->weight = 1.0f;
-                               break;
-                       case WEIGHT_SUBTRACT:
-                               dw->weight -= weight;
-                               /* if the weight is zero or less then
-                                * remove the vert from the deform group
-                                */
-                               if (dw->weight <= 0.0f) {
-                                       defvert_remove_group(dv, dw);
-                               }
-                               break;
+                       switch (assignmode) {
+                               case WEIGHT_REPLACE:
+                                       dw->weight = weight;
+                                       break;
+                               case WEIGHT_ADD:
+                                       dw->weight += weight;
+                                       if (dw->weight >= 1.0f)
+                                               dw->weight = 1.0f;
+                                       break;
+                               case WEIGHT_SUBTRACT:
+                                       dw->weight -= weight;
+                                       /* if the weight is zero or less then
+                                        * remove the vert from the deform group
+                                        */
+                                       if (dw->weight <= 0.0f) {
+                                               defvert_remove_group(dv, dw);
+                                       }
+                                       break;
                        }
                }
                else {
                         * we must take a different form of action ...
                         */
  
-                       switch(assignmode) {
-                       case WEIGHT_SUBTRACT:
-                               /* if we are subtracting then we don't
-                                * need to do anything
-                                */
-                               return;
+                       switch (assignmode) {
+                               case WEIGHT_SUBTRACT:
+                                       /* if we are subtracting then we don't
+                                        * need to do anything
+                                        */
+                                       return;
  
-                       case WEIGHT_REPLACE:
-                       case WEIGHT_ADD:
-                               /* if we are doing an additive assignment, then
-                                * we need to create the deform weight
-                                */
+                               case WEIGHT_REPLACE:
+                               case WEIGHT_ADD:
+                                       /* if we are doing an additive assignment, then
+                                        * we need to create the deform weight
+                                        */
  
-                               /* we checked if the vertex was added before so no need to test again, simply add */
-                               defvert_add_index_notest(dv, def_nr, weight);
+                                       /* we checked if the vertex was added before so no need to test again, simply add */
+                                       defvert_add_index_notest(dv, def_nr, weight);
                        }
                }
        }
@@@ -666,9 -463,9 +666,9 @@@ void ED_vgroup_vert_add(Object *ob, bDe
        /* add the vert to the deform group with the
         * specified assign mode
         */
-       const int def_nr= BLI_findindex(&ob->defbase, dg);
+       const int def_nr = BLI_findindex(&ob->defbase, dg);
  
-       MDeformVert *dv= NULL;
+       MDeformVert *dv = NULL;
        int tot;
  
        /* get the deform group number, exit if
  
        /* if there's no deform verts then create some,
         */
-       if (ED_vgroup_give_array(ob->data, &dv, &tot) && dv==NULL)
+       if (ED_vgroup_give_array(ob->data, &dv, &tot) && dv == NULL)
                ED_vgroup_data_create(ob->data);
  
        /* call another function to do the work
  }
  
  /* mesh object mode, lattice can be in editmode */
- void ED_vgroup_vert_remove(Object *ob, bDeformGroup   *dg, int vertnum)
+ void ED_vgroup_vert_remove(Object *ob, bDeformGroup *dg, int vertnum)
  {
        /* This routine removes the vertex from the specified
         * deform group.
         */
  
        /* TODO, this is slow in a loop, better pass def_nr directly, but leave for later... - campbell */
-       const int def_nr= BLI_findindex(&ob->defbase, dg);
+       const int def_nr = BLI_findindex(&ob->defbase, dg);
  
        if (def_nr != -1) {
-               MDeformVert *dvert= NULL;
+               MDeformVert *dvert = NULL;
                int tot;
  
                /* get the deform vertices corresponding to the
                ED_vgroup_give_array(ob->data, &dvert, &tot);
  
                if (dvert) {
-                       MDeformVert *dv= &dvert[vertnum];
+                       MDeformVert *dv = &dvert[vertnum];
                        MDeformWeight *dw;
  
-                       dw= defvert_find_index(dv, def_nr);
+                       dw = defvert_find_index(dv, def_nr);
                        defvert_remove_group(dv, dw); /* dw can be NULL */
                }
        }
  
  static float get_vert_def_nr(Object *ob, const int def_nr, const int vertnum)
  {
-       MDeformVert *dv= NULL;
+       MDeformVert *dv = NULL;
        BMVert *eve;
        Mesh *me;
  
        /* get the deform vertices corresponding to the vertnum */
-       if (ob->type==OB_MESH) {
-               me= ob->data;
+       if (ob->type == OB_MESH) {
+               me = ob->data;
  
                if (me->edit_btmesh) {
-                       eve= BM_vert_at_index(me->edit_btmesh->bm, vertnum);
+                       eve = BM_vert_at_index(me->edit_btmesh->bm, vertnum);
                        if (!eve) {
                                return 0.0f;
                        }
-                       dv= CustomData_bmesh_get(&me->edit_btmesh->bm->vdata, eve->head.data, CD_MDEFORMVERT);
+                       dv = CustomData_bmesh_get(&me->edit_btmesh->bm->vdata, eve->head.data, CD_MDEFORMVERT);
                }
                else {
                        if (vertnum >= me->totvert) {
                        dv = &me->dvert[vertnum];
                }
        }
-       else if (ob->type==OB_LATTICE) {
-               Lattice *lt= vgroup_edit_lattice(ob);
+       else if (ob->type == OB_LATTICE) {
+               Lattice *lt = vgroup_edit_lattice(ob);
  
                if (lt->dvert) {
-                       if (vertnum >= lt->pntsu*lt->pntsv*lt->pntsw) {
+                       if (vertnum >= lt->pntsu * lt->pntsv * lt->pntsw) {
                                return 0.0f;
                        }
                        dv = &lt->dvert[vertnum];
        }
        
        if (dv) {
-               MDeformWeight *dw= defvert_find_index(dv, def_nr);
+               MDeformWeight *dw = defvert_find_index(dv, def_nr);
                if (dw) {
                        return dw->weight;
                }
  
  float ED_vgroup_vert_weight(Object *ob, bDeformGroup *dg, int vertnum)
  {
-       const int def_nr= BLI_findindex(&ob->defbase, dg);
+       const int def_nr = BLI_findindex(&ob->defbase, dg);
  
        if (def_nr == -1) {
                return -1;
  }
  
  void ED_vgroup_select_by_name(Object *ob, const char *name)
- {     /* note: ob->actdef==0 signals on painting to create a new one, if a bone in posemode is selected */
-       ob->actdef= defgroup_name_index(ob, name) + 1;
+ {   /* note: ob->actdef==0 signals on painting to create a new one, if a bone in posemode is selected */
+       ob->actdef = defgroup_name_index(ob, name) + 1;
  }
  
  /********************** Operator Implementations *********************/
  /* only in editmode */
  static void vgroup_select_verts(Object *ob, int select)
  {
-       const int def_nr= ob->actdef-1;
+       const int def_nr = ob->actdef - 1;
        MDeformVert *dv;
  
        if (!BLI_findlink(&ob->defbase, def_nr)) {
        }
  
        if (ob->type == OB_MESH) {
-               Mesh *me= ob->data;
+               Mesh *me = ob->data;
  
                if (me->edit_btmesh) {
                        BMEditMesh *em = me->edit_btmesh;
  
                        BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
                                if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
-                                       dv= CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT);
+                                       dv = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT);
                                        if (defvert_find_index(dv, def_nr)) {
                                                BM_vert_select_set(em->bm, eve, select);
                                        }
                        }
  
                        /* this has to be called, because this function operates on vertices only */
-                       if (select) EDBM_select_flush(em);      // vertices to edges/faces
+                       if (select) EDBM_select_flush(em);  // vertices to edges/faces
                        else EDBM_deselect_flush(em);
                }
                else {
                                mv = me->mvert;
                                dv = me->dvert;
  
-                               for (i=0; i<me->totvert; i++, mv++, dv++) {
+                               for (i = 0; i < me->totvert; i++, mv++, dv++) {
                                        if (!(mv->flag & ME_HIDE)) {
                                                if (defvert_find_index(dv, def_nr)) {
-                                                       if (select)  mv->flag |=  SELECT;
-                                                       else         mv->flag &= ~SELECT;
+                                                       if (select) mv->flag |=  SELECT;
+                                                       else mv->flag &= ~SELECT;
                                                }
                                        }
                                }
                }
        }
        else if (ob->type == OB_LATTICE) {
-               Lattice *lt= vgroup_edit_lattice(ob);
+               Lattice *lt = vgroup_edit_lattice(ob);
                
                if (lt->dvert) {
                        BPoint *bp;
                        int a, tot;
                        
-                       dv= lt->dvert;
+                       dv = lt->dvert;
  
-                       tot= lt->pntsu*lt->pntsv*lt->pntsw;
-                       for (a=0, bp= lt->def; a<tot; a++, bp++, dv++) {
+                       tot = lt->pntsu * lt->pntsv * lt->pntsw;
+                       for (a = 0, bp = lt->def; a < tot; a++, bp++, dv++) {
                                if (defvert_find_index(dv, def_nr)) {
-                                       if (select)  bp->f1 |=  SELECT;
-                                       else         bp->f1 &= ~SELECT;
+                                       if (select) bp->f1 |=  SELECT;
+                                       else bp->f1 &= ~SELECT;
                                }
                        }
                }
@@@ -856,10 -653,10 +856,10 @@@ static void vgroup_duplicate(Object *ob
        bDeformGroup *dg, *cdg;
        char name[sizeof(dg->name)];
        MDeformWeight *dw_org, *dw_cpy;
-       MDeformVert **dvert_array=NULL;
-       int i, idg, icdg, dvert_tot=0;
+       MDeformVert **dvert_array = NULL;
+       int i, idg, icdg, dvert_tot = 0;
  
-       dg = BLI_findlink(&ob->defbase, (ob->actdef-1));
+       dg = BLI_findlink(&ob->defbase, (ob->actdef - 1));
        if (!dg)
                return;
        
  
        BLI_addtail(&ob->defbase, cdg);
  
-       idg = (ob->actdef-1);
+       idg = (ob->actdef - 1);
        ob->actdef = BLI_countlist(&ob->defbase);
-       icdg = (ob->actdef-1);
+       icdg = (ob->actdef - 1);
  
        /* TODO, we might want to allow only copy selected verts here? - campbell */
        ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot, FALSE);
  
        if (dvert_array) {
                for (i = 0; i < dvert_tot; i++) {
-                       MDeformVert *dv= dvert_array[i];
+                       MDeformVert *dv = dvert_array[i];
                        dw_org = defvert_find_index(dv, idg);
                        if (dw_org) {
                                /* defvert_verify_index re-allocs org so need to store the weight first */
  static void vgroup_normalize(Object *ob)
  {
        MDeformWeight *dw;
-       MDeformVert *dv, **dvert_array=NULL;
-       int i, dvert_tot=0;
-       const int def_nr= ob->actdef-1;
+       MDeformVert *dv, **dvert_array = NULL;
+       int i, dvert_tot = 0;
+       const int def_nr = ob->actdef - 1;
  
        const int use_vert_sel = (ob->type == OB_MESH && ((Mesh *)ob->data)->editflag & ME_EDIT_VERT_SEL) != 0;
  
  /* This finds all of the vertices face-connected to vert by an edge and returns a
   * MEM_allocated array of indices of size count.
   * count is an int passed by reference so it can be assigned the value of the length here. */
- static intgetSurroundingVerts(Mesh *me, int vert, int *count)
+ static int *getSurroundingVerts(Mesh *me, int vert, int *count)
  {
        MPoly *mp = me->mpoly;
        int i = me->totpoly;
                                }
                                else if (!j) {
                                        /* We are on the last corner. */
-                                       a = (ml-1)->v;
+                                       a = (ml - 1)->v;
                                        b = me->mloop[mp->loopstart].v;
                                }
                                else {
-                                       a = (ml-1)->v;
-                                       b = (ml+1)->v;
+                                       a = (ml - 1)->v;
+                                       b = (ml + 1)->v;
                                }
  
                                /* Append a and b verts to array, if not yet present. */
@@@ -1026,7 -823,7 +1026,7 @@@ static void getSingleCoordinate(MVert *
        for (i = 0; i < count; i++) {
                add_v3_v3(coord, points[i].co);
        }
-       mul_v3_fl(coord, 1.0f/count);
+       mul_v3_fl(coord, 1.0f / count);
  }
  
  /* given a plane and a start and end position,
@@@ -1056,7 -853,7 +1056,7 @@@ static void getVerticalAndHorizontalCha
  // I need the derived mesh to be forgotten so the positions are recalculated with weight changes (see dm_deform_recalc)
  static void dm_deform_clear(DerivedMesh *dm, Object *ob)
  {
-       if (ob->derivedDeform && (ob->derivedDeform)==dm) {
+       if (ob->derivedDeform && (ob->derivedDeform) == dm) {
                ob->derivedDeform->needsFree = 1;
                ob->derivedDeform->release(ob->derivedDeform);
                ob->derivedDeform = NULL;
  }
  
  /* recalculate the deformation */
- static DerivedMeshdm_deform_recalc(Scene *scene, Object *ob)
+ static DerivedMesh *dm_deform_recalc(Scene *scene, Object *ob)
  {
        return mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH);
  }
@@@ -1088,19 -885,19 +1088,19 @@@ static void moveCloserToDistanceFromPla
        DerivedMesh *dm;
        MDeformWeight *dw;
        MVert m;
-       MDeformVert *dvert = me->dvert+index;
+       MDeformVert *dvert = me->dvert + index;
        int totweight = dvert->totweight;
        float oldw = 0;
        float oldPos[3] = {0};
        float vc, hc, dist = 0.0f;
        int i, k;
-       float (*changes)[2] = MEM_mallocN(sizeof(float *)*totweight*2, "vertHorzChange");
-       float *dists = MEM_mallocN(sizeof(float)*totweight, "distance");
+       float (*changes)[2] = MEM_mallocN(sizeof(float *) * totweight * 2, "vertHorzChange");
+       float *dists = MEM_mallocN(sizeof(float) * totweight, "distance");
  
        /* track if up or down moved it closer for each bone */
-       int *upDown = MEM_callocN(sizeof(int)*totweight, "upDownTracker");
+       int *upDown = MEM_callocN(sizeof(int) * totweight, "upDownTracker");
  
-       int *dwIndices = MEM_callocN(sizeof(int)*totweight, "dwIndexTracker");
+       int *dwIndices = MEM_callocN(sizeof(int) * totweight, "dwIndexTracker");
        float distToStart;
        int bestIndex = 0;
        char wasChange;
                distToStart = dot_v3v3(norm, oldPos) + d;
  
                if (distToBe == originalDistToBe) {
-                       distToBe += distToStart - distToStart*strength;
+                       distToBe += distToStart - distToStart * strength;
                }
                for (i = 0; i < totweight; i++) {
                        dwIndices[i] = i;
-                       dw = (dvert->dw+i);
+                       dw = (dvert->dw + i);
                        vc = hc = 0;
                        if (!dw->weight) {
                                changes[i][0] = 0;
                                }
                                oldw = dw->weight;
                                if (k) {
-                                       dw->weight *= 1+cp;
+                                       dw->weight *= 1 + cp;
                                }
                                else {
-                                       dw->weight /= 1+cp;
+                                       dw->weight /= 1 + cp;
                                }
                                if (dw->weight == oldw) {
                                        changes[i][0] = 0;
                        float tf;
                        int ti;
                        bestIndex = k;
-                       for (i = k+1; i < totweight; i++) {
+                       for (i = k + 1; i < totweight; i++) {
                                dist = dists[i];
  
                                if (fabs(dist) > fabs(dists[i])) {
                bestIndex = -1;
                // find the best change with an acceptable horizontal change
                for (i = 0; i < totweight; i++) {
-                       if (fabs(changes[i][0]) > fabs(changes[i][1]*2.0f)) {
+                       if (fabs(changes[i][0]) > fabs(changes[i][1] * 2.0f)) {
                                bestIndex = i;
                                break;
                        }
                        }
                        lastIndex = bestIndex;
                        wasUp = upDown[bestIndex];
-                       dw = (dvert->dw+dwIndices[bestIndex]);
+                       dw = (dvert->dw + dwIndices[bestIndex]);
                        oldw = dw->weight;
                        if (upDown[bestIndex]) {
-                               dw->weight *= 1+cp;
+                               dw->weight *= 1 + cp;
                        }
                        else {
-                               dw->weight /= 1+cp;
+                               dw->weight /= 1 + cp;
                        }
                        if (dw->weight > 1) {
                                dw->weight = 1;
                                dm_deform_clear(dm, ob); dm = NULL;
                        }
                }
-       } while (wasChange && (distToStart-distToBe)/fabsf(distToStart-distToBe) ==
-                            (dists[bestIndex]-distToBe)/fabsf(dists[bestIndex]-distToBe));
+       } while (wasChange && ((distToStart - distToBe) / fabsf(distToStart - distToBe) ==
+                              (dists[bestIndex] - distToBe) / fabsf(dists[bestIndex] - distToBe)));
        MEM_freeN(upDown);
        MEM_freeN(changes);
        MEM_freeN(dists);
@@@ -1267,10 -1065,10 +1268,10 @@@ static void vgroup_fix(Scene *scene, Ob
                return;
        for (i = 0; i < me->totvert && mvert; i++, mvert++) {
                if (mvert->flag & SELECT) {
-                       int count=0;
+                       int count = 0;
                        if ((verts = getSurroundingVerts(me, i, &count))) {
                                MVert m;
-                               MVert *p = MEM_callocN(sizeof(MVert)*(count), "deformedPoints");
+                               MVert *p = MEM_callocN(sizeof(MVert) * (count), "deformedPoints");
                                int k;
  
                                DerivedMesh *dm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH);
                                        getSingleCoordinate(p, count, coord);
                                        dm->getVert(dm, i, &m);
                                        sub_v3_v3v3(norm, m.co, coord);
-                                       mag= normalize_v3(norm);
+                                       mag = normalize_v3(norm);
                                        if (mag) { /* zeros fix */
                                                d = -dot_v3v3(norm, coord);
                                                /* dist = (dot_v3v3(norm, m.co) + d); */ /* UNUSED */
  static void vgroup_levels(Object *ob, float offset, float gain)
  {
        MDeformWeight *dw;
-       MDeformVert *dv, **dvert_array=NULL;
-       int i, dvert_tot=0;
-       const int def_nr= ob->actdef-1;
+       MDeformVert *dv, **dvert_array = NULL;
+       int i, dvert_tot = 0;
+       const int def_nr = ob->actdef - 1;
  
        const int use_vert_sel = (ob->type == OB_MESH && ((Mesh *)ob->data)->editflag & ME_EDIT_VERT_SEL) != 0;
  
  /* TODO - select between groups */
  static void vgroup_normalize_all(Object *ob, int lock_active)
  {
-       MDeformVert *dv, **dvert_array=NULL;
-       int i, dvert_tot=0;
-       const int def_nr= ob->actdef-1;
+       MDeformVert *dv, **dvert_array = NULL;
+       int i, dvert_tot = 0;
+       const int def_nr = ob->actdef - 1;
  
        const int use_vert_sel = (ob->type == OB_MESH && ((Mesh *)ob->data)->editflag & ME_EDIT_VERT_SEL) != 0;
  
        }
  }
  
 -
  static void vgroup_lock_all(Object *ob, int action)
  {
        bDeformGroup *dg;
  
        if (action == SEL_TOGGLE) {
-               action= SEL_SELECT;
-               for (dg= ob->defbase.first; dg; dg= dg->next) {
+               action = SEL_SELECT;
+               for (dg = ob->defbase.first; dg; dg = dg->next) {
                        if (dg->flag & DG_LOCK_WEIGHT) {
-                               action= SEL_DESELECT;
+                               action = SEL_DESELECT;
                                break;
                        }
                }
        }
  
-       for (dg= ob->defbase.first; dg; dg= dg->next) {
-               switch(action) {
+       for (dg = ob->defbase.first; dg; dg = dg->next) {
+               switch (action) {
                        case SEL_SELECT:
                                dg->flag |= DG_LOCK_WEIGHT;
                                break;
  static void vgroup_invert(Object *ob, const short auto_assign, const short auto_remove)
  {
        MDeformWeight *dw;
-       MDeformVert *dv, **dvert_array=NULL;
-       int i, dvert_tot=0;
-       const int def_nr= ob->actdef-1;
+       MDeformVert *dv, **dvert_array = NULL;
+       int i, dvert_tot = 0;
+       const int def_nr = ob->actdef - 1;
        const int use_vert_sel = (ob->type == OB_MESH && ((Mesh *)ob->data)->editflag & ME_EDIT_VERT_SEL) != 0;
  
        if (!BLI_findlink(&ob->defbase, def_nr)) {
                        }
  
                        if (auto_assign) {
-                               dw= defvert_verify_index(dv, def_nr);
+                               dw = defvert_verify_index(dv, def_nr);
                        }
                        else {
-                               dw= defvert_find_index(dv, def_nr);
+                               dw = defvert_find_index(dv, def_nr);
                        }
  
                        if (dw) {
@@@ -1455,8 -1254,8 +1456,8 @@@ static void vgroup_blend(Object *ob, co
  {
        MDeformVert *dv;
        MDeformWeight *dw;
-       int i, dvert_tot=0;
-       const int def_nr= ob->actdef - 1;
+       int i, dvert_tot = 0;
+       const int def_nr = ob->actdef - 1;
  
        BLI_assert(fac >= 0.0 && fac <= 1.0f);
  
                                        int i1 /* , i2 */;
                                        /* i1 is always the selected one */
                                        if (sel1) {
-                                               i1= BM_elem_index_get(eed->v1);
+                                               i1 = BM_elem_index_get(eed->v1);
                                                /* i2= BM_elem_index_get(eed->v2); */ /* UNUSED */
-                                               eve= eed->v2;
+                                               eve = eed->v2;
                                        }
                                        else {
                                                /* i2= BM_elem_index_get(eed->v1); */ /* UNUSED */
-                                               i1= BM_elem_index_get(eed->v2);
-                                               eve= eed->v1;
+                                               i1 = BM_elem_index_get(eed->v2);
+                                               eve = eed->v1;
                                        }
  
                                        dv = CustomData_bmesh_get(&bm->vdata, eve->head.data, CD_MDEFORMVERT);
  static void vgroup_clean(Object *ob, const float epsilon, int keep_single)
  {
        MDeformWeight *dw;
-       MDeformVert *dv, **dvert_array=NULL;
-       int i, dvert_tot=0;
-       const int def_nr= ob->actdef-1;
+       MDeformVert *dv, **dvert_array = NULL;
+       int i, dvert_tot = 0;
+       const int def_nr = ob->actdef - 1;
        const int use_vert_sel = (ob->type == OB_MESH && ((Mesh *)ob->data)->editflag & ME_EDIT_VERT_SEL) != 0;
  
        if (!BLI_findlink(&ob->defbase, def_nr)) {
                                continue;
                        }
  
-                       dw= defvert_find_index(dv, def_nr);
+                       dw = defvert_find_index(dv, def_nr);
  
                        if (dw) {
                                if (dw->weight <= epsilon) {
-                                       if (keep_single==FALSE || dv->totweight > 1) {
+                                       if (keep_single == FALSE || dv->totweight > 1) {
                                                defvert_remove_group(dv, dw); /* dw can be NULL */
                                        }
                                }
  
  static void vgroup_clean_all(Object *ob, const float epsilon, const int keep_single)
  {
-       MDeformVert **dvert_array=NULL;
+       MDeformVert **dvert_array = NULL;
        int i, dvert_tot = 0;
        const int use_vert_sel = (ob->type == OB_MESH && ((Mesh *)ob->data)->editflag & ME_EDIT_VERT_SEL) != 0;
  
                                continue;
                        }
  
-                       j= dv->totweight;
+                       j = dv->totweight;
  
                        while (j--) {
  
                                if (keep_single && dv->totweight == 1)
                                        break;
  
-                               dw= dv->dw + j;
+                               dw = dv->dw + j;
  
                                if (dw->weight <= epsilon) {
                                        defvert_remove_group(dv, dw);
@@@ -1676,14 -1475,14 +1677,14 @@@ static void dvert_mirror_op(MDeformVer
                                SWAP(MDeformVert, *dvert, *dvert_mirr);
                        }
                        else {
-                               MDeformWeight *dw=      defvert_find_index(dvert, act_vgroup);
-                               MDeformWeight *dw_mirr= defvert_find_index(dvert_mirr, act_vgroup);
+                               MDeformWeight *dw =      defvert_find_index(dvert, act_vgroup);
+                               MDeformWeight *dw_mirr = defvert_find_index(dvert_mirr, act_vgroup);
  
                                if (dw || dw_mirr) {
                                        if (dw_mirr == NULL)
-                                               dw_mirr= defvert_verify_index(dvert_mirr, act_vgroup);
+                                               dw_mirr = defvert_verify_index(dvert_mirr, act_vgroup);
                                        if (dw == NULL)
-                                               dw= defvert_verify_index(dvert, act_vgroup);
+                                               dw = defvert_verify_index(dvert, act_vgroup);
  
                                        SWAP(float, dw->weight, dw_mirr->weight);
                                }
@@@ -1733,19 -1532,19 +1734,19 @@@ void ED_vgroup_mirror(Object *ob, cons
        BMVert *eve, *eve_mirr;
        MDeformVert *dvert, *dvert_mirr;
        short sel, sel_mirr;
-       int     *flip_map, flip_map_len;
-       const int def_nr= ob->actdef-1;
+       int *flip_map, flip_map_len;
+       const int def_nr = ob->actdef - 1;
  
-       if ( (mirror_weights==0 && flip_vgroups==0) ||
+       if ( (mirror_weights == 0 && flip_vgroups == 0) ||
             (BLI_findlink(&ob->defbase, def_nr) == NULL) )
        {
                return;
        }
  
        if (flip_vgroups) {
-               flip_map= all_vgroups ?
-                                       defgroup_flip_map(ob, &flip_map_len, FALSE) :
-                                       defgroup_flip_map_single(ob, &flip_map_len, FALSE, def_nr);
+               flip_map = all_vgroups ?
+                          defgroup_flip_map(ob, &flip_map_len, FALSE) :
+                          defgroup_flip_map_single(ob, &flip_map_len, FALSE, def_nr);
  
                BLI_assert(flip_map != NULL);
  
                }
        }
        else {
-               flip_map= NULL;
-               flip_map_len= 0;
+               flip_map = NULL;
+               flip_map_len = 0;
        }
  
        /* only the active group */
        if (ob->type == OB_MESH) {
-               Mesh *me= ob->data;
+               Mesh *me = ob->data;
                BMEditMesh *em = me->edit_btmesh;
  
                if (em) {
  
                        /* Go through the list of editverts and assign them */
                        BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
-                               if ((eve_mirr= EDBM_verts_mirror_get(em, eve))) {
-                                       sel= BM_elem_flag_test(eve, BM_ELEM_SELECT);
-                                       sel_mirr= BM_elem_flag_test(eve_mirr, BM_ELEM_SELECT);
+                               if ((eve_mirr = EDBM_verts_mirror_get(em, eve))) {
+                                       sel = BM_elem_flag_test(eve, BM_ELEM_SELECT);
+                                       sel_mirr = BM_elem_flag_test(eve_mirr, BM_ELEM_SELECT);
  
                                        if ((sel || sel_mirr) && (eve != eve_mirr)) {
-                                               dvert= CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT);
-                                               dvert_mirr= CustomData_bmesh_get(&em->bm->vdata, eve_mirr->head.data, CD_MDEFORMVERT);
+                                               dvert = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT);
+                                               dvert_mirr = CustomData_bmesh_get(&em->bm->vdata, eve_mirr->head.data, CD_MDEFORMVERT);
                                                if (dvert && dvert_mirr) {
                                                        VGROUP_MIRR_OP;
                                                }
                        }
  
                        if (!use_vert_sel) {
-                               sel= sel_mirr= TRUE;
+                               sel = sel_mirr = TRUE;
                        }
  
                        /* tag verts we have used */
-                       for (vidx= 0, mv= me->mvert; vidx < me->totvert; vidx++, mv++) {
+                       for (vidx = 0, mv = me->mvert; vidx < me->totvert; vidx++, mv++) {
                                mv->flag &= ~ME_VERT_TMP_TAG;
                        }
  
-                       for (vidx= 0, mv= me->mvert; vidx < me->totvert; vidx++, mv++) {
+                       for (vidx = 0, mv = me->mvert; vidx < me->totvert; vidx++, mv++) {
                                if (    ((mv->flag & ME_VERT_TMP_TAG) == 0) &&
-                                       ((vidx_mirr= mesh_get_x_mirror_vert(ob, vidx)) != -1) &&
+                                       ((vidx_mirr = mesh_get_x_mirror_vert(ob, vidx)) != -1) &&
                                        (vidx != vidx_mirr) &&
-                                       ((((mv_mirr= me->mvert + vidx_mirr)->flag) & ME_VERT_TMP_TAG) == 0))
+                                       ((((mv_mirr = me->mvert + vidx_mirr)->flag) & ME_VERT_TMP_TAG) == 0))
                                {
  
                                        if (use_vert_sel) {
-                                               sel= mv->flag & SELECT;
-                                               sel_mirr= mv_mirr->flag & SELECT;
+                                               sel = mv->flag & SELECT;
+                                               sel_mirr = mv_mirr->flag & SELECT;
                                        }
  
                                        if (sel || sel_mirr) {
-                                               dvert= &me->dvert[vidx];
-                                               dvert_mirr= &me->dvert[vidx_mirr];
+                                               dvert = &me->dvert[vidx];
+                                               dvert_mirr = &me->dvert[vidx_mirr];
  
                                                VGROUP_MIRR_OP;
                                        }
                }
        }
        else if (ob->type == OB_LATTICE) {
-               Lattice *lt= vgroup_edit_lattice(ob);
+               Lattice *lt = vgroup_edit_lattice(ob);
                int i1, i2;
                int u, v, w;
                int pntsu_half;
                /* unlike editmesh we know that by only looping over the first half of
                 * the 'u' indices it will cover all points except the middle which is
                 * ok in this case */
-               pntsu_half= lt->pntsu / 2;
+               pntsu_half = lt->pntsu / 2;
  
-               for (w=0; w<lt->pntsw; w++) {
-                       for (v=0; v<lt->pntsv; v++) {
-                               for (u=0; u<pntsu_half; u++) {
-                                       int u_inv= (lt->pntsu - 1) - u;
+               for (w = 0; w < lt->pntsw; w++) {
+                       for (v = 0; v < lt->pntsv; v++) {
+                               for (u = 0; u < pntsu_half; u++) {
+                                       int u_inv = (lt->pntsu - 1) - u;
                                        if (u != u_inv) {
                                                BPoint *bp, *bp_mirr;
  
-                                               i1= LT_INDEX(lt, u, v, w);
-                                               i2= LT_INDEX(lt, u_inv, v, w);
+                                               i1 = LT_INDEX(lt, u, v, w);
+                                               i2 = LT_INDEX(lt, u_inv, v, w);
  
-                                               bp= &lt->def[i1];
-                                               bp_mirr= &lt->def[i2];
+                                               bp = &lt->def[i1];
+                                               bp_mirr = &lt->def[i2];
  
-                                               sel= bp->f1 & SELECT;
-                                               sel_mirr= bp_mirr->f1 & SELECT;
+                                               sel = bp->f1 & SELECT;
+                                               sel_mirr = bp_mirr->f1 & SELECT;
  
                                                if (sel || sel_mirr) {
-                                                       dvert= &lt->dvert[i1];
-                                                       dvert_mirr= &lt->dvert[i2];
+                                                       dvert = &lt->dvert[i1];
+                                                       dvert_mirr = &lt->dvert[i2];
  
                                                        VGROUP_MIRR_OP;
                                                }
@@@ -1902,40 -1701,40 +1903,40 @@@ static void vgroup_remap_update_users(O
         * they get deleted the numbers get out of sync, this corrects that */
  
        if (ob->soft)
-               ob->soft->vertgroup= map[ob->soft->vertgroup];
+               ob->soft->vertgroup = map[ob->soft->vertgroup];
  
-       for (md=ob->modifiers.first; md; md=md->next) {
+       for (md = ob->modifiers.first; md; md = md->next) {
                if (md->type == eModifierType_Explode) {
-                       emd= (ExplodeModifierData*)md;
-                       emd->vgroup= map[emd->vgroup];
+                       emd = (ExplodeModifierData *)md;
+                       emd->vgroup = map[emd->vgroup];
                }
                else if (md->type == eModifierType_Cloth) {
-                       clmd= (ClothModifierData*)md;
-                       clsim= clmd->sim_parms;
+                       clmd = (ClothModifierData *)md;
+                       clsim = clmd->sim_parms;
  
                        if (clsim) {
-                               clsim->vgroup_mass= map[clsim->vgroup_mass];
-                               clsim->vgroup_bend= map[clsim->vgroup_bend];
-                               clsim->vgroup_struct= map[clsim->vgroup_struct];
+                               clsim->vgroup_mass = map[clsim->vgroup_mass];
+                               clsim->vgroup_bend = map[clsim->vgroup_bend];
+                               clsim->vgroup_struct = map[clsim->vgroup_struct];
                        }
                }
        }
  
-       for (psys=ob->particlesystem.first; psys; psys=psys->next) {
-               for (a=0; a<PSYS_TOT_VG; a++)
-                       psys->vgroup[a]= map[psys->vgroup[a]];
+       for (psys = ob->particlesystem.first; psys; psys = psys->next) {
+               for (a = 0; a < PSYS_TOT_VG; a++)
+                       psys->vgroup[a] = map[psys->vgroup[a]];
        }
  }
  
  
  static void vgroup_delete_update_users(Object *ob, int id)
  {
-       int i, defbase_tot= BLI_countlist(&ob->defbase) + 1;
-       int *map= MEM_mallocN(sizeof(int) * defbase_tot, "vgroup del");
+       int i, defbase_tot = BLI_countlist(&ob->defbase) + 1;
+       int *map = MEM_mallocN(sizeof(int) * defbase_tot, "vgroup del");
  
-       map[id]= map[0]= 0;
-       for (i=1; i<id; i++) map[i]=i;
-       for (i=id+1; i<defbase_tot; i++) map[i]=i-1;
+       map[id] = map[0] = 0;
+       for (i = 1; i < id; i++) map[i] = i;
+       for (i = id + 1; i < defbase_tot; i++) map[i] = i - 1;
  
        vgroup_remap_update_users(ob, map);
        MEM_freeN(map);
  
  static void vgroup_delete_object_mode(Object *ob, bDeformGroup *dg)
  {
-       MDeformVert *dvert_array=NULL;
-       int dvert_tot=0;
-       const int def_nr= BLI_findindex(&ob->defbase, dg);
+       MDeformVert *dvert_array = NULL;
+       int dvert_tot = 0;
+       const int def_nr = BLI_findindex(&ob->defbase, dg);
  
        assert(def_nr > -1);
  
        if (dvert_array) {
                int i, j;
                MDeformVert *dv;
-               for (i= 0, dv= dvert_array; i < dvert_tot; i++, dv++) {
+               for (i = 0, dv = dvert_array; i < dvert_tot; i++, dv++) {
                        MDeformWeight *dw;
  
-                       dw= defvert_find_index(dv, def_nr);
+                       dw = defvert_find_index(dv, def_nr);
                        defvert_remove_group(dv, dw); /* dw can be NULL */
  
                        /* inline, make into a function if anything else needs to do this */
        if (ob->actdef > def_nr)
                ob->actdef--;
        if (ob->actdef < 1 && ob->defbase.first)
-               ob->actdef= 1;
+               ob->actdef = 1;
  
  }
  
  static void vgroup_active_remove_verts(Object *ob, const int allverts, bDeformGroup *dg)
  {
        MDeformVert *dv;
-       const int def_nr= BLI_findindex(&ob->defbase, dg);
+       const int def_nr = BLI_findindex(&ob->defbase, dg);
  
        if (ob->type == OB_MESH) {
-               Mesh *me= ob->data;
+               Mesh *me = ob->data;
  
                if (me->edit_btmesh) {
                        BMEditMesh *em = me->edit_btmesh;
                        BMIter iter;
  
                        BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
-                               dv= CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT);
+                               dv = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT);
  
                                if (dv && dv->dw && (allverts || BM_elem_flag_test(eve, BM_ELEM_SELECT))) {
                                        MDeformWeight *dw = defvert_find_index(dv, def_nr);
                        mv = me->mvert;
                        dv = me->dvert;
  
-                       for (i=0; i<me->totvert; i++, mv++, dv++) {
+                       for (i = 0; i < me->totvert; i++, mv++, dv++) {
                                if (mv->flag & SELECT) {
                                        if (dv->dw && (allverts || (mv->flag & SELECT))) {
                                                MDeformWeight *dw = defvert_find_index(dv, def_nr);
                }
        }
        else if (ob->type == OB_LATTICE) {
-               Lattice *lt= vgroup_edit_lattice(ob);
+               Lattice *lt = vgroup_edit_lattice(ob);
                
                if (lt->dvert) {
                        BPoint *bp;
-                       int i, tot= lt->pntsu*lt->pntsv*lt->pntsw;
+                       int i, tot = lt->pntsu * lt->pntsv * lt->pntsw;
                                
-                       for (i=0, bp= lt->def; i<tot; i++, bp++) {
+                       for (i = 0, bp = lt->def; i < tot; i++, bp++) {
                                if (allverts || (bp->f1 & SELECT)) {
                                        MDeformWeight *dw;
  
-                                       dv= &lt->dvert[i];
+                                       dv = &lt->dvert[i];
  
                                        dw = defvert_find_index(dv, def_nr);
                                        defvert_remove_group(dv, dw); /* dw can be NULL */
  static void vgroup_delete_edit_mode(Object *ob, bDeformGroup *dg)
  {
        int i;
-       const int dg_index= BLI_findindex(&ob->defbase, dg);
+       const int dg_index = BLI_findindex(&ob->defbase, dg);
  
        assert(dg_index > -1);
  
        vgroup_active_remove_verts(ob, TRUE, dg);
  
        /* Make sure that any verts with higher indices are adjusted accordingly */
-       if (ob->type==OB_MESH) {
-               Mesh *me= ob->data;
+       if (ob->type == OB_MESH) {
+               Mesh *me = ob->data;
                BMEditMesh *em = me->edit_btmesh;
                BMIter iter;
                BMVert *eve;
                MDeformVert *dvert;
                
                BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
-                       dvert= CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT);
+                       dvert = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT);
  
                        if (dvert)
-                               for (i=0; i<dvert->totweight; i++)
+                               for (i = 0; i < dvert->totweight; i++)
                                        if (dvert->dw[i].def_nr > dg_index)
                                                dvert->dw[i].def_nr--;
                }
        }
-       else if (ob->type==OB_LATTICE) {
-               Lattice *lt= vgroup_edit_lattice(ob);
+       else if (ob->type == OB_LATTICE) {
+               Lattice *lt = vgroup_edit_lattice(ob);
                BPoint *bp;
-               MDeformVert *dvert= lt->dvert;
+               MDeformVert *dvert = lt->dvert;
                int a, tot;
                
                if (dvert) {
-                       tot= lt->pntsu*lt->pntsv*lt->pntsw;
-                       for (a=0, bp= lt->def; a<tot; a++, bp++, dvert++) {
-                               for (i=0; i<dvert->totweight; i++) {
+                       tot = lt->pntsu * lt->pntsv * lt->pntsw;
+                       for (a = 0, bp = lt->def; a < tot; a++, bp++, dvert++) {
+                               for (i = 0; i < dvert->totweight; i++) {
                                        if (dvert->dw[i].def_nr > dg_index)
                                                dvert->dw[i].def_nr--;
                                }
        vgroup_delete_update_users(ob, dg_index + 1);
  
        /* Remove the group */
-       BLI_freelinkN (&ob->defbase, dg);
+       BLI_freelinkN(&ob->defbase, dg);
  
        /* Update the active deform index if necessary */
        if (ob->actdef > dg_index)
                ob->actdef--;
        if (ob->actdef < 1 && ob->defbase.first)
-               ob->actdef= 1;
+               ob->actdef = 1;
  
        /* remove all dverts */
        if (ob->defbase.first == NULL) {
-               if (ob->type==OB_MESH) {
-                       Mesh *me= ob->data;
+               if (ob->type == OB_MESH) {
+                       Mesh *me = ob->data;
                        CustomData_free_layer_active(&me->vdata, CD_MDEFORMVERT, me->totvert);
-                       me->dvert= NULL;
+                       me->dvert = NULL;
                }
-               else if (ob->type==OB_LATTICE) {
-                       Lattice *lt= vgroup_edit_lattice(ob);
+               else if (ob->type == OB_LATTICE) {
+                       Lattice *lt = vgroup_edit_lattice(ob);
                        if (lt->dvert) {
                                MEM_freeN(lt->dvert);
-                               lt->dvert= NULL;
+                               lt->dvert = NULL;
                        }
                }
        }
@@@ -2128,7 -1927,7 +2129,7 @@@ static int vgroup_object_in_edit_mode(O
        if (ob->type == OB_MESH)
                return (BMEdit_FromObject(ob) != NULL);
        else if (ob->type == OB_LATTICE)
-               return (((Lattice*)ob->data)->editlatt != NULL);
+               return (((Lattice *)ob->data)->editlatt != NULL);
        
        return 0;
  }
@@@ -2147,7 -1946,7 +2148,7 @@@ static int vgroup_object_in_wpaint_vert
  
  static void vgroup_delete(Object *ob)
  {
-       bDeformGroup *dg = BLI_findlink(&ob->defbase, ob->actdef-1);
+       bDeformGroup *dg = BLI_findlink(&ob->defbase, ob->actdef - 1);
        if (!dg)
                return;
  
  static void vgroup_delete_all(Object *ob)
  {
        /* Remove all DVerts */
-       if (ob->type==OB_MESH) {
-               Mesh *me= ob->data;
+       if (ob->type == OB_MESH) {
+               Mesh *me = ob->data;
                CustomData_free_layer_active(&me->vdata, CD_MDEFORMVERT, me->totvert);
-               me->dvert= NULL;
+               me->dvert = NULL;
        }
-       else if (ob->type==OB_LATTICE) {
-               Lattice *lt= vgroup_edit_lattice(ob);
+       else if (ob->type == OB_LATTICE) {
+               Lattice *lt = vgroup_edit_lattice(ob);
                if (lt->dvert) {
                        MEM_freeN(lt->dvert);
-                       lt->dvert= NULL;
+                       lt->dvert = NULL;
                }
        }
        
        BLI_freelistN(&ob->defbase);
        
        /* Fix counters/indices */
-       ob->actdef= 0;
+       ob->actdef = 0;
  }
  
  /* only in editmode */
  static void vgroup_assign_verts(Object *ob, const float weight)
  {
        MDeformVert *dv;
-       const int def_nr= ob->actdef-1;
+       const int def_nr = ob->actdef - 1;
  
        if (!BLI_findlink(&ob->defbase, def_nr))
                return;
  
        if (ob->type == OB_MESH) {
-               Mesh *me= ob->data;
+               Mesh *me = ob->data;
  
                if (me->edit_btmesh) {
                        BMEditMesh *em = me->edit_btmesh;
                        BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
                                if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
                                        MDeformWeight *dw;
-                                       dv= CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT); /* can be NULL */
-                                       dw= defvert_verify_index(dv, def_nr);
+                                       dv = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT); /* can be NULL */
+                                       dw = defvert_verify_index(dv, def_nr);
                                        if (dw) {
-                                               dw->weight= weight;
+                                               dw->weight = weight;
                                        }
                                }
                        }
                        mv = me->mvert;
                        dv = me->dvert;
  
-                       for (i=0; i<me->totvert; i++, mv++, dv++) {
+                       for (i = 0; i < me->totvert; i++, mv++, dv++) {
                                if (mv->flag & SELECT) {
                                        MDeformWeight *dw;
-                                       dw= defvert_verify_index(dv, def_nr);
+                                       dw = defvert_verify_index(dv, def_nr);
                                        if (dw) {
-                                               dw->weight= weight;
+                                               dw->weight = weight;
                                        }
                                }
                        }
                }
        }
        else if (ob->type == OB_LATTICE) {
-               Lattice *lt= vgroup_edit_lattice(ob);
+               Lattice *lt = vgroup_edit_lattice(ob);
                BPoint *bp;
                int a, tot;
  
-               if (lt->dvert==NULL)
+               if (lt->dvert == NULL)
                        ED_vgroup_data_create(&lt->id);
  
-               dv= lt->dvert;
+               dv = lt->dvert;
  
-               tot= lt->pntsu*lt->pntsv*lt->pntsw;
-               for (a=0, bp= lt->def; a<tot; a++, bp++, dv++) {
+               tot = lt->pntsu * lt->pntsv * lt->pntsw;
+               for (a = 0, bp = lt->def; a < tot; a++, bp++, dv++) {
                        if (bp->f1 & SELECT) {
                                MDeformWeight *dw;
  
-                               dw= defvert_verify_index(dv, def_nr);
+                               dw = defvert_verify_index(dv, def_nr);
                                if (dw) {
-                                       dw->weight= weight;
+                                       dw->weight = weight;
                                }
                        }
                }
@@@ -2268,7 -2067,7 +2269,7 @@@ static void vgroup_remove_verts(Object 
         * active group index
         */
        bDeformGroup *dg;
-       for (dg= ob->defbase.first; dg; dg= dg->next) {
+       for (dg = ob->defbase.first; dg; dg = dg->next) {
                vgroup_active_remove_verts(ob, allverts, dg);
        }
  }
  
  static int vertex_group_poll(bContext *C)
  {
-       Object *ob= ED_object_context(C);
-       ID *data= (ob)? ob->data: NULL;
+       Object *ob = ED_object_context(C);
+       ID *data = (ob) ? ob->data : NULL;
        return (ob && !ob->id.lib && OB_TYPE_SUPPORT_VGROUP(ob->type) && data && !data->lib);
  }
  
- static int UNUSED_FUNCTION(vertex_group_poll_edit)(bContext *C)
+ static int UNUSED_FUNCTION(vertex_group_poll_edit) (bContext * C)
  {
-       Object *ob= ED_object_context(C);
-       ID *data= (ob)? ob->data: NULL;
+       Object *ob = ED_object_context(C);
+       ID *data = (ob) ? ob->data : NULL;
  
        if (!(ob && !ob->id.lib && data && !data->lib))
                return 0;
  /* editmode _or_ weight paint vertex sel */
  static int vertex_group_poll_edit_or_wpaint_vert_select(bContext *C)
  {
-       Object *ob= ED_object_context(C);
-       ID *data= (ob)? ob->data: NULL;
+       Object *ob = ED_object_context(C);
+       ID *data = (ob) ? ob->data : NULL;
  
        if (!(ob && !ob->id.lib && data && !data->lib))
                return 0;
  
-       return ( vgroup_object_in_edit_mode(ob) ||
-                vgroup_object_in_wpaint_vert_select(ob) );
+       return (vgroup_object_in_edit_mode(ob) ||
+               vgroup_object_in_wpaint_vert_select(ob));
  }
  
  static int vertex_group_add_exec(bContext *C, wmOperator *UNUSED(op))
  {
-       Object *ob= ED_object_context(C);
+       Object *ob = ED_object_context(C);
  
        ED_vgroup_add(ob);
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data);
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
+       WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
+       WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
        
        return OPERATOR_FINISHED;
  }
@@@ -2329,12 -2128,12 +2330,12 @@@ void OBJECT_OT_vertex_group_add(wmOpera
        ot->exec = vertex_group_add_exec;
  
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
  }
  
  static int vertex_group_remove_exec(bContext *C, wmOperator *op)
  {
-       Object *ob= ED_object_context(C);
+       Object *ob = ED_object_context(C);
  
        if (RNA_boolean_get(op->ptr, "all"))
                vgroup_delete_all(ob);
                vgroup_delete(ob);
  
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data);
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
+       WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
+       WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
        
        return OPERATOR_FINISHED;
  }
@@@ -2362,7 -2161,7 +2363,7 @@@ void OBJECT_OT_vertex_group_remove(wmOp
        /* redo operator will fail in this case because vertex groups aren't stored
         * in local edit mode stack and toggling "all" property will lead to
         * all groups deleted without way to restore them (see [#29527], sergey) */
-       ot->flag = /*OPTYPE_REGISTER|*/OPTYPE_UNDO;
+       ot->flag = /*OPTYPE_REGISTER|*/ OPTYPE_UNDO;
  
        /* properties */
        RNA_def_boolean(ot->srna, "all", 0, "All", "Remove from all vertex groups");
  
  static int vertex_group_assign_exec(bContext *C, wmOperator *op)
  {
-       ToolSettings *ts= CTX_data_tool_settings(C);
-       Object *ob= ED_object_context(C);
+       ToolSettings *ts = CTX_data_tool_settings(C);
+       Object *ob = ED_object_context(C);
  
        if (RNA_boolean_get(op->ptr, "new"))
                ED_vgroup_add(ob);
  
        vgroup_assign_verts(ob, ts->vgroup_weight);
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data);
+       WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
        
        return OPERATOR_FINISHED;
  }
@@@ -2397,7 -2196,7 +2398,7 @@@ void OBJECT_OT_vertex_group_assign(wmOp
        /* redo operator will fail in this case because vertex group assignment
         * isn't stored in local edit mode stack and toggling "new" property will
         * lead to creating plenty of new vertex groups (see [#29527], sergey) */
-       ot->flag = /*OPTYPE_REGISTER|*/OPTYPE_UNDO;
+       ot->flag = /*OPTYPE_REGISTER|*/ OPTYPE_UNDO;
  
        /* properties */
        RNA_def_boolean(ot->srna, "new", 0, "New", "Assign vertex to new vertex group");
  
  static int vertex_group_remove_from_exec(bContext *C, wmOperator *op)
  {
-       Object *ob= ED_object_context(C);
+       Object *ob = ED_object_context(C);
  
        if (RNA_boolean_get(op->ptr, "all"))
                vgroup_remove_verts(ob, 0);
        else {
-               bDeformGroup *dg= BLI_findlink(&ob->defbase, ob->actdef - 1);
+               bDeformGroup *dg = BLI_findlink(&ob->defbase, ob->actdef - 1);
  
                if (dg == NULL) {
                        return OPERATOR_CANCELLED;
        }
  
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data);
+       WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
  
        return OPERATOR_FINISHED;
  }
@@@ -2439,7 -2238,7 +2440,7 @@@ void OBJECT_OT_vertex_group_remove_from
        /* redo operator will fail in this case because vertex groups assignment
         * isn't stored in local edit mode stack and toggling "all" property will lead to
         * removing vertices from all groups (see [#29527], sergey) */
-       ot->flag = /*OPTYPE_REGISTER|*/OPTYPE_UNDO;
+       ot->flag = /*OPTYPE_REGISTER|*/ OPTYPE_UNDO;
  
        /* properties */
        RNA_def_boolean(ot->srna, "all", 0, "All", "Remove from all vertex groups");
  
  static int vertex_group_select_exec(bContext *C, wmOperator *UNUSED(op))
  {
-       Object *ob= ED_object_context(C);
+       Object *ob = ED_object_context(C);
  
        if (!ob || ob->id.lib)
                return OPERATOR_CANCELLED;
  
        vgroup_select_verts(ob, 1);
-       WM_event_add_notifier(C, NC_GEOM|ND_SELECT, ob->data);
+       WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob->data);
  
        return OPERATOR_FINISHED;
  }
@@@ -2469,15 -2268,15 +2470,15 @@@ void OBJECT_OT_vertex_group_select(wmOp
        ot->exec = vertex_group_select_exec;
  
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
  }
  
  static int vertex_group_deselect_exec(bContext *C, wmOperator *UNUSED(op))
  {
-       Object *ob= ED_object_context(C);
+       Object *ob = ED_object_context(C);
  
        vgroup_select_verts(ob, 0);
-       WM_event_add_notifier(C, NC_GEOM|ND_SELECT, ob->data);
+       WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob->data);
  
        return OPERATOR_FINISHED;
  }
@@@ -2493,18 -2292,17 +2494,18 @@@ void OBJECT_OT_vertex_group_deselect(wm
        ot->exec = vertex_group_deselect_exec;
  
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
  }
  
 +/*Adds a copy of selected vertex group from source object to source object*/
  static int vertex_group_copy_exec(bContext *C, wmOperator *UNUSED(op))
  {
-       Object *ob= ED_object_context(C);
+       Object *ob = ED_object_context(C);
  
        vgroup_duplicate(ob);
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data);
+       WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
+       WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
  
        return OPERATOR_FINISHED;
  }
@@@ -2520,21 -2318,21 +2521,21 @@@ void OBJECT_OT_vertex_group_copy(wmOper
        ot->exec = vertex_group_copy_exec;
  
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
  }
  
  static int vertex_group_levels_exec(bContext *C, wmOperator *op)
  {
-       Object *ob= ED_object_context(C);
+       Object *ob = ED_object_context(C);
        
-       float offset= RNA_float_get(op->ptr,"offset");
-       float gain= RNA_float_get(op->ptr,"gain");
+       float offset = RNA_float_get(op->ptr, "offset");
+       float gain = RNA_float_get(op->ptr, "gain");
        
        vgroup_levels(ob, offset, gain);
        
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data);
+       WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
+       WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
        
        return OPERATOR_FINISHED;
  }
@@@ -2550,7 -2348,7 +2551,7 @@@ void OBJECT_OT_vertex_group_levels(wmOp
        ot->exec = vertex_group_levels_exec;
        
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
        RNA_def_float(ot->srna, "offset", 0.f, -1.0, 1.0, "Offset", "Value to add to weights", -1.0f, 1.f);
        RNA_def_float(ot->srna, "gain", 1.f, 0.f, FLT_MAX, "Gain", "Value to multiply weights by", 0.0f, 10.f);
  
  static int vertex_group_normalize_exec(bContext *C, wmOperator *UNUSED(op))
  {
-       Object *ob= ED_object_context(C);
+       Object *ob = ED_object_context(C);
  
        vgroup_normalize(ob);
  
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data);
+       WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
+       WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
  
        return OPERATOR_FINISHED;
  }
@@@ -2580,19 -2378,19 +2581,19 @@@ void OBJECT_OT_vertex_group_normalize(w
        ot->exec = vertex_group_normalize_exec;
  
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
  }
  
  static int vertex_group_normalize_all_exec(bContext *C, wmOperator *op)
  {
-       Object *ob= ED_object_context(C);
-       int lock_active= RNA_boolean_get(op->ptr,"lock_active");
+       Object *ob = ED_object_context(C);
+       int lock_active = RNA_boolean_get(op->ptr, "lock_active");
  
        vgroup_normalize_all(ob, lock_active);
  
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data);
+       WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
+       WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
  
        return OPERATOR_FINISHED;
  }
@@@ -2608,7 -2406,7 +2609,7 @@@ void OBJECT_OT_vertex_group_normalize_a
        ot->exec = vertex_group_normalize_all_exec;
  
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
  
        RNA_def_boolean(ot->srna, "lock_active", TRUE, "Lock Active",
                        "Keep the values of the active group while normalizing others");
  
  static int vertex_group_fix_exec(bContext *C, wmOperator *op)
  {
-       Object *ob= CTX_data_active_object(C);
-       Scene *scene= CTX_data_scene(C);
+       Object *ob = CTX_data_active_object(C);
+       Scene *scene = CTX_data_scene(C);
        
-       float distToBe= RNA_float_get(op->ptr, "dist");
-       float strength= RNA_float_get(op->ptr, "strength");
-       float cp= RNA_float_get(op->ptr, "accuracy");
-       ModifierData *md= ob->modifiers.first;
+       float distToBe = RNA_float_get(op->ptr, "dist");
+       float strength = RNA_float_get(op->ptr, "strength");
+       float cp = RNA_float_get(op->ptr, "accuracy");
+       ModifierData *md = ob->modifiers.first;
  
        while (md) {
-               if (md->type == eModifierType_Mirror && (md->mode&eModifierMode_Realtime)) {
+               if (md->type == eModifierType_Mirror && (md->mode & eModifierMode_Realtime)) {
                        break;
                }
                md = md->next;
        vgroup_fix(scene, ob, distToBe, strength, cp);
        
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data);
+       WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
+       WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
        
        return OPERATOR_FINISHED;
  }
@@@ -2650,14 -2448,14 +2651,14 @@@ void OBJECT_OT_vertex_group_fix(wmOpera
        ot->name = "Fix Vertex Group Deform";
        ot->idname = "OBJECT_OT_vertex_group_fix";
        ot->description = "Modify the position of selected vertices by changing only their respective "
-                        "groups' weights (this tool may be slow for many vertices)";
+                         "groups' weights (this tool may be slow for many vertices)";
        
        /* api callbacks */
        ot->poll = vertex_group_poll;
        ot->exec = vertex_group_fix_exec;
        
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        RNA_def_float(ot->srna, "dist", 0.0f, -FLT_MAX, FLT_MAX, "Distance", "The distance to move to", -10.0f, 10.0f);
        RNA_def_float(ot->srna, "strength", 1.f, -2.0f, FLT_MAX, "Strength",
                      "The distance moved can be changed by this multiplier", -2.0f, 2.0f);
  
  static int vertex_group_lock_exec(bContext *C, wmOperator *op)
  {
-       Object *ob= CTX_data_active_object(C);
+       Object *ob = CTX_data_active_object(C);
  
        int action = RNA_enum_get(op->ptr, "action");
  
@@@ -2688,21 -2486,21 +2689,21 @@@ void OBJECT_OT_vertex_group_lock(wmOper
        ot->exec = vertex_group_lock_exec;
  
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
  
        WM_operator_properties_select_all(ot);
  }
  
  static int vertex_group_invert_exec(bContext *C, wmOperator *op)
  {
-       Object *ob= ED_object_context(C);
-       int auto_assign= RNA_boolean_get(op->ptr,"auto_assign");
-       int auto_remove= RNA_boolean_get(op->ptr,"auto_remove");
+       Object *ob = ED_object_context(C);
+       int auto_assign = RNA_boolean_get(op->ptr, "auto_assign");
+       int auto_remove = RNA_boolean_get(op->ptr, "auto_remove");
  
        vgroup_invert(ob, auto_assign, auto_remove);
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data);
+       WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
+       WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
  
        return OPERATOR_FINISHED;
  }
@@@ -2718,7 -2516,7 +2719,7 @@@ void OBJECT_OT_vertex_group_invert(wmOp
        ot->exec = vertex_group_invert_exec;
  
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
  
        RNA_def_boolean(ot->srna, "auto_assign", TRUE, "Add Weights",
                        "Add verts from groups that have zero weight before inverting");
@@@ -2735,8 -2533,8 +2736,8 @@@ static int vertex_group_blend_exec(bCon
        vgroup_blend(ob, fac);
  
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data);
+       WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
+       WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
  
        return OPERATOR_FINISHED;
  }
  static int vertex_group_blend_poll(bContext *C)
  {
        Object *ob = ED_object_context(C);
-       ID *data = (ob) ? ob->data: NULL;
+       ID *data = (ob) ? ob->data : NULL;
  
        if (!(ob && !ob->id.lib && data && !data->lib))
                return FALSE;
@@@ -2782,7 -2580,7 +2783,7 @@@ void OBJECT_OT_vertex_group_blend(wmOpe
        ot->exec = vertex_group_blend_exec;
  
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
  
        prop = RNA_def_property(ot->srna, "factor", PROP_FLOAT, PROP_FACTOR);
        RNA_def_property_ui_text(prop, "Factor", "");
  
  static int vertex_group_clean_exec(bContext *C, wmOperator *op)
  {
-       Object *ob= ED_object_context(C);
+       Object *ob = ED_object_context(C);
  
-       float limit= RNA_float_get(op->ptr,"limit");
-       int all_groups= RNA_boolean_get(op->ptr,"all_groups");
-       int keep_single= RNA_boolean_get(op->ptr,"keep_single");
+       float limit = RNA_float_get(op->ptr, "limit");
+       int all_groups = RNA_boolean_get(op->ptr, "all_groups");
+       int keep_single = RNA_boolean_get(op->ptr, "keep_single");
  
-       if (all_groups) vgroup_clean_all(ob, limit, keep_single);
-       else                    vgroup_clean(ob, limit, keep_single);
+       if (all_groups) vgroup_clean_all(ob, limit, keep_single);
+       else vgroup_clean(ob, limit, keep_single);
  
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data);
+       WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
+       WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
  
        return OPERATOR_FINISHED;
  }
@@@ -2821,7 -2619,7 +2822,7 @@@ void OBJECT_OT_vertex_group_clean(wmOpe
        ot->exec = vertex_group_clean_exec;
  
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
  
        RNA_def_float(ot->srna, "limit", 0.01f, 0.0f, 1.0, "Limit", "Remove weights under this limit", 0.001f, 0.99f);
        RNA_def_boolean(ot->srna, "all_groups", FALSE, "All Groups", "Clean all vertex groups");
  
  static int vertex_group_mirror_exec(bContext *C, wmOperator *op)
  {
-       Object *ob= ED_object_context(C);
+       Object *ob = ED_object_context(C);
  
        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, "mirror_weights"),
+                        RNA_boolean_get(op->ptr, "flip_group_names"),
+                        RNA_boolean_get(op->ptr, "all_groups"));
  
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data);
+       WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
+       WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
  
        return OPERATOR_FINISHED;
  }
@@@ -2852,14 -2650,14 +2853,14 @@@ void OBJECT_OT_vertex_group_mirror(wmOp
        ot->name = "Mirror Vertex Group";
        ot->idname = "OBJECT_OT_vertex_group_mirror";
        ot->description = "Mirror all vertex groups, flip weights and/or names, editing only selected vertices, "
-                        "flipping when both sides are selected otherwise copy from unselected";
+                         "flipping when both sides are selected otherwise copy from unselected";
  
        /* api callbacks */
        ot->poll = vertex_group_poll;
        ot->exec = vertex_group_mirror_exec;
  
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
  
        /* properties */
        RNA_def_boolean(ot->srna, "mirror_weights", TRUE, "Mirror Weights", "Mirror weights");
  
  static int vertex_group_copy_to_linked_exec(bContext *C, wmOperator *UNUSED(op))
  {
-       Scene *scene= CTX_data_scene(C);
-       Object *ob= ED_object_context(C);
+       Scene *scene = CTX_data_scene(C);
+       Object *ob = ED_object_context(C);
        Base *base;
-       int retval= OPERATOR_CANCELLED;
+       int retval = OPERATOR_CANCELLED;
  
-       for (base=scene->base.first; base; base= base->next) {
-               if (base->object->type==ob->type) {
-                       if (base->object!=ob && base->object->data==ob->data) {
+       for (base = scene->base.first; base; base = base->next) {
+               if (base->object->type == ob->type) {
+                       if (base->object != ob && base->object->data == ob->data) {
                                BLI_freelistN(&base->object->defbase);
                                BLI_duplicatelist(&base->object->defbase, &ob->defbase);
-                               base->object->actdef= ob->actdef;
+                               base->object->actdef = ob->actdef;
  
                                DAG_id_tag_update(&base->object->id, OB_RECALC_DATA);
-                               WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, base->object);
-                               WM_event_add_notifier(C, NC_GEOM|ND_DATA, base->object->data);
+                               WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, base->object);
+                               WM_event_add_notifier(C, NC_GEOM | ND_DATA, base->object->data);
  
                                retval = OPERATOR_FINISHED;
                        }
@@@ -2906,21 -2704,19 +2907,20 @@@ void OBJECT_OT_vertex_group_copy_to_lin
        ot->exec = vertex_group_copy_to_linked_exec;
  
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
  }
  
 +/*Copy vertex groups from source to target*/ /*warning! overwrites list*/
  static int vertex_group_copy_to_selected_exec(bContext *C, wmOperator *op)
  {
-       Object *obact= ED_object_context(C);
-       int change= 0;
-       int fail= 0;
+       Object *obact = ED_object_context(C);
+       int change = 0;
+       int fail = 0;
  
-       CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects)
-       {
+       CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
                if (obact != ob) {
                        if (ED_vgroup_copy_array(ob, obact)) change++;
-                       else                                fail++;
+                       else fail++;
                }
        }
        CTX_DATA_END;
        return OPERATOR_FINISHED;
  }
  
 -
 +/* Transfer all vertex groups with weight to selected*/
  void OBJECT_OT_vertex_group_copy_to_selected(wmOperatorType *ot)
  {
        /* identifiers */
 -      ot->name = "Copy Vertex Group to Selected";
 -      ot->idname = "OBJECT_OT_vertex_group_copy_to_selected";
 -      ot->description = "Copy Vertex Groups to other selected objects with matching indices";
 +      ot->name= "Copy Vertex Group to Selected";
 +      ot->idname= "OBJECT_OT_vertex_group_copy_to_selected";
 +      ot->description= "Copy Vertex Groups to other selected objects with matching indices";
  
        /* api callbacks */
 -      ot->poll = vertex_group_poll;
 -      ot->exec = vertex_group_copy_to_selected_exec;
 +      ot->poll= vertex_group_poll;
 +      ot->exec= vertex_group_copy_to_selected_exec;
  
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
  }
  
- static EnumPropertyItem vgroup_items[]= {
-       {0, NULL, 0, NULL, NULL}};
 +static int vertex_group_copy_to_selected_single_exec(bContext *C, wmOperator *op)
 +{
 +      Object *obact= CTX_data_active_object(C);
 +      int change= 0;
 +      int fail= 0;
 +
 +      /*Macro to loop through selected objects and perform operation*/
 +      CTX_DATA_BEGIN(C, Object*, obslc, selected_editable_objects)
 +      {
 +              if(obact != obslc) {
 +                      /*Try function for matching number of vertices*/
 +                      if(ED_vgroup_copy_single(obslc, obact)) change++;
 +                      /*Try function for get weight from closest vertex*/
 +                      /*TODO: try this function*/
 +                      /*Try function for get weight from closest face*/
 +                      else if(ED_vgroup_copy_by_nearest_face_single(obslc, obact)) change++;
 +                      /*Trigger error message*/
 +                      else fail++;
 +                      /*Event notifiers for correct display of data*/
 +                      DAG_id_tag_update(&obslc->id, OB_RECALC_DATA);
 +                      WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obslc);
 +                      WM_event_add_notifier(C, NC_GEOM|ND_DATA, obslc->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, All functions failed!",
 +                          change, fail);
 +      }
 +
 +      return OPERATOR_FINISHED;
 +}
 +
 +/*Transfer vertex group with weight to selected*/
 +void OBJECT_OT_vertex_group_copy_to_selected_single(wmOperatorType *ot)
 +{
 +      /* identifiers */
 +      ot->name= "Copy a Vertex Group to Selected";
 +      ot->idname= "OBJECT_OT_vertex_group_copy_to_selected_single";
 +      ot->description= "Copy a vertex group to other selected objects with matching indices";
 +
 +      /* api callbacks */
 +      ot->poll= vertex_group_poll;
 +      ot->exec= vertex_group_copy_to_selected_single_exec;
 +
 +      /* flags */
 +      ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 +}
 +
+ static EnumPropertyItem vgroup_items[] = {
+       {0, NULL, 0, NULL, NULL}
+ };
  
  static int set_active_group_exec(bContext *C, wmOperator *op)
  {
-       Object *ob= ED_object_context(C);
-       int nr= RNA_enum_get(op->ptr, "group");
+       Object *ob = ED_object_context(C);
+       int nr = RNA_enum_get(op->ptr, "group");
  
-       BLI_assert(nr+1 >= 0);
-       ob->actdef= nr+1;
+       BLI_assert(nr + 1 >= 0);
+       ob->actdef = nr + 1;
  
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob);
+       WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob);
  
        return OPERATOR_FINISHED;
  }
  
  static EnumPropertyItem *vgroup_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free)
  {     
-       Object *ob= ED_object_context(C);
+       Object *ob = ED_object_context(C);
        EnumPropertyItem tmp = {0, "", 0, "", ""};
-       EnumPropertyItem *item= NULL;
+       EnumPropertyItem *item = NULL;
        bDeformGroup *def;
-       int a, totitem= 0;
+       int a, totitem = 0;
        
        if (!ob)
                return vgroup_items;
        
-       for (a=0, def=ob->defbase.first; def; def=def->next, a++) {
-               tmp.value= a;
-               tmp.icon= ICON_GROUP_VERTEX;
-               tmp.identifier= def->name;
-               tmp.name= def->name;
+       for (a = 0, def = ob->defbase.first; def; def = def->next, a++) {
+               tmp.value = a;
+               tmp.icon = ICON_GROUP_VERTEX;
+               tmp.identifier = def->name;
+               tmp.name = def->name;
                RNA_enum_item_add(&item, &totitem, &tmp);
        }
  
        RNA_enum_item_end(&item, &totitem);
-       *free= 1;
+       *free = 1;
  
        return item;
  }
@@@ -3059,10 -2804,10 +3060,10 @@@ void OBJECT_OT_vertex_group_set_active(
        ot->invoke = WM_menu_invoke;
  
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
  
        /* properties */
-       prop= RNA_def_enum(ot->srna, "group", vgroup_items, 0, "Group", "Vertex group to set as active");
+       prop = RNA_def_enum(ot->srna, "group", vgroup_items, 0, "Group", "Vertex group to set as active");
        RNA_def_enum_funcs(prop, vgroup_itemf);
        ot->prop = prop;
  }
@@@ -3073,11 -2818,11 +3074,11 @@@ static char *vgroup_init_remap(Object *
  {
        bDeformGroup *def;
        int defbase_tot = BLI_countlist(&ob->defbase);
-       char *name_array= MEM_mallocN(MAX_VGROUP_NAME * sizeof(char) * defbase_tot, "sort vgroups");
+       char *name_array = MEM_mallocN(MAX_VGROUP_NAME * sizeof(char) * defbase_tot, "sort vgroups");
        char *name;
  
-       name= name_array;
-       for (def = ob->defbase.first; def; def=def->next) {
+       name = name_array;
+       for (def = ob->defbase.first; def; def = def->next) {
                BLI_strncpy(name, def->name, MAX_VGROUP_NAME);
                name += MAX_VGROUP_NAME;
        }
  
  static int vgroup_do_remap(Object *ob, char *name_array, wmOperator *op)
  {
-       MDeformVert *dvert= NULL;
+       MDeformVert *dvert = NULL;
        bDeformGroup *def;
        int defbase_tot = BLI_countlist(&ob->defbase);
  
        /* needs a dummy index at the start*/
-       int *sort_map_update= MEM_mallocN(sizeof(int) * (defbase_tot + 1), "sort vgroups");
-       int *sort_map= sort_map_update + 1;
+       int *sort_map_update = MEM_mallocN(sizeof(int) * (defbase_tot + 1), "sort vgroups");
+       int *sort_map = sort_map_update + 1;
  
        char *name;
        int i;
  
-       name= name_array;
-       for (def= ob->defbase.first, i=0; def; def=def->next, i++) {
-               sort_map[i]= BLI_findstringindex(&ob->defbase, name, offsetof(bDeformGroup, name));
+       name = name_array;
+       for (def = ob->defbase.first, i = 0; def; def = def->next, i++) {
+               sort_map[i] = BLI_findstringindex(&ob->defbase, name, offsetof(bDeformGroup, name));
                name += MAX_VGROUP_NAME;
  
                BLI_assert(sort_map[i] != -1);
        }
  
        if (ob->mode == OB_MODE_EDIT) {
-               if (ob->type==OB_MESH) {
+               if (ob->type == OB_MESH) {
                        BMEditMesh *em = BMEdit_FromObject(ob);
                        BMIter iter;
                        BMVert *eve;
  
                        BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
-                               dvert= CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT);
+                               dvert = CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT);
                                if (dvert && dvert->totweight) {
                                        defvert_remap(dvert, sort_map, defbase_tot);
                                }
                }
        }
        else {
-               int dvert_tot=0;
+               int dvert_tot = 0;
  
                ED_vgroup_give_array(ob->data, &dvert, &dvert_tot);
  
        }
  
        /* update users */
-       for (i=0; i<defbase_tot; i++)
+       for (i = 0; i < defbase_tot; i++)
                sort_map[i]++;
  
-       sort_map_update[0]= 0;
+       sort_map_update[0] = 0;
        vgroup_remap_update_users(ob, sort_map_update);
  
        BLI_assert(sort_map_update[ob->actdef] >= 0);
-       ob->actdef= sort_map_update[ob->actdef];
+       ob->actdef = sort_map_update[ob->actdef];
        
        MEM_freeN(sort_map_update);
  
  
  static int vgroup_sort(void *def_a_ptr, void *def_b_ptr)
  {
-       bDeformGroup *def_a= (bDeformGroup *)def_a_ptr;
-       bDeformGroup *def_b= (bDeformGroup *)def_b_ptr;
+       bDeformGroup *def_a = (bDeformGroup *)def_a_ptr;
+       bDeformGroup *def_b = (bDeformGroup *)def_b_ptr;
  
        return BLI_natstrcmp(def_a->name, def_b->name);
  }
  
  static int vertex_group_sort_exec(bContext *C, wmOperator *op)
  {
-       Object *ob= ED_object_context(C);
+       Object *ob = ED_object_context(C);
        char *name_array;
        int ret;
  
  
        if (ret != OPERATOR_CANCELLED) {
                DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-               WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob);
+               WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob);
        }
  
        if (name_array) MEM_freeN(name_array);
@@@ -3197,15 -2942,15 +3198,15 @@@ void OBJECT_OT_vertex_group_sort(wmOper
        ot->exec = vertex_group_sort_exec;
  
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
  }
  
  static int vgroup_move_exec(bContext *C, wmOperator *op)
  {
-       Object *ob= ED_object_context(C);
+       Object *ob = ED_object_context(C);
        bDeformGroup *def;
        char *name_array;
-       int dir= RNA_enum_get(op->ptr, "direction"), ret;
+       int dir = RNA_enum_get(op->ptr, "direction"), ret;
  
        def = BLI_findlink(&ob->defbase, ob->actdef - 1);
        if (!def) {
  
        if (ret != OPERATOR_CANCELLED) {
                DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-               WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob);
+               WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob);
        }
  
        return ret;
@@@ -3256,7 -3001,7 +3257,7 @@@ void OBJECT_OT_vertex_group_move(wmOper
        ot->exec = vgroup_move_exec;
  
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
  
        RNA_def_enum(ot->srna, "direction", vgroup_slot_move, 0, "Direction", "Direction to move, UP or DOWN");
  }