Refactor: Move part of vgroup handling code from ED_mesh/object_vgroup.c to BKE_objec...
authorBastien Montagne <montagne29@wanadoo.fr>
Tue, 18 Nov 2014 22:52:17 +0000 (23:52 +0100)
committerBastien Montagne <montagne29@wanadoo.fr>
Tue, 18 Nov 2014 22:52:29 +0000 (23:52 +0100)
Along with some minor cleanup and simplifications.

Reviewers: campbellbarton

Subscribers: sergey

Differential Revision: https://developer.blender.org/D903

14 files changed:
source/blender/blenkernel/BKE_object_deform.h
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/object_deform.c
source/blender/collada/SkinInfo.cpp
source/blender/editors/armature/armature_skinning.c
source/blender/editors/include/ED_mesh.h
source/blender/editors/include/ED_object.h
source/blender/editors/object/object_modifier.c
source/blender/editors/object/object_vgroup.c
source/blender/editors/physics/dynamicpaint_ops.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/editors/space_view3d/view3d_buttons.c
source/blender/makesrna/intern/rna_object.c
source/blenderplayer/bad_level_call_stubs/stubs.c

index 6de7ff9bc1c83eb8bb196c1ba37642a1c67f72f6..0e5ad2d51c8626491c4e191d3baa89f864e77b47 100644 (file)
  *        used by painting and tools.
  */
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 struct Object;
+struct ID;
+struct MDeformVert;
+struct bDeformGroup;
+
+/* General vgroup operations */
+void BKE_object_defgroup_remap_update_users(struct Object *ob, int *map);
+
+bool BKE_object_defgroup_array_get(struct ID *id, struct MDeformVert **dvert_arr, int *dvert_tot);
+
+struct bDeformGroup *BKE_object_defgroup_add(struct Object *ob);
+struct bDeformGroup *BKE_object_defgroup_add_name(struct Object *ob, const char *name);
+struct MDeformVert  *BKE_object_defgroup_data_create(struct ID *id);
+
+bool BKE_object_defgroup_clear(struct Object *ob, struct bDeformGroup *dg, const bool use_selection);
+bool BKE_object_defgroup_clear_all(struct Object *ob, const bool use_selection);
+
+void BKE_object_defgroup_remove(struct Object *ob, struct bDeformGroup *defgroup);
+void BKE_object_defgroup_remove_all(struct Object *ob);
+
+
+/* Select helpers */
+enum eVGroupSelect;
+bool *BKE_object_defgroup_subset_from_select_type(
+        struct Object *ob, enum eVGroupSelect subset_type, int *r_defgroup_tot, int *r_subset_count);
+void BKE_object_defgroup_subset_to_index_array(
+        const bool *defgroup_validmap, const int defgroup_tot, int *r_defgroup_subset_map);
+
+
+/* ********** */
+
+bool *BKE_object_defgroup_lock_flags_get(struct Object *ob, const int defbase_tot);
+bool *BKE_object_defgroup_validmap_get(struct Object *ob, const int defbase_tot);
+bool *BKE_object_defgroup_selected_get(struct Object *ob, int defbase_tot, int *r_dg_flags_sel_tot);
 
-bool *BKE_objdef_lock_flags_get(struct Object *ob, const int defbase_tot);
-bool *BKE_objdef_validmap_get(struct Object *ob, const int defbase_tot);
-bool *BKE_objdef_selected_get(struct Object *ob, int defbase_tot, int *r_dg_flags_sel_tot);
+#ifdef __cplusplus
+}
+#endif
 
 #endif  /* __BKE_OBJECT_DEFORM_H__ */
index 0d029b161ffa215f583ca5c4bdeb9bf74a61e076..bd357541256521a390fb7894d815858ce423f4ac 100644 (file)
@@ -1228,7 +1228,7 @@ static void calc_weightpaint_vert_array(Object *ob, DerivedMesh *dm, int const d
                bool *defbase_sel = NULL;
 
                if (draw_flag & CALC_WP_MULTIPAINT) {
-                       defbase_sel = BKE_objdef_selected_get(ob, defbase_tot, &defbase_sel_tot);
+                       defbase_sel = BKE_object_defgroup_selected_get(ob, defbase_tot, &defbase_sel_tot);
                }
 
                for (i = numVerts; i != 0; i--, wc++, dv++) {
index a3f5e56f4dceeafc103f9a959e95dad2cd08715f..e46929dde4ad66dec1113c00888a6eb702bc9974 100644 (file)
 
 #include "MEM_guardedalloc.h"
 
+#include "BLF_translation.h"
+
 #include "BLI_utildefines.h"
 #include "BLI_ghash.h"
 #include "BLI_listbase.h"
 
+#include "DNA_armature_types.h"
+#include "DNA_cloth_types.h"
+#include "DNA_curve_types.h"
+#include "DNA_lattice_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_object_types.h"
+#include "DNA_object_force.h"
+#include "DNA_particle_types.h"
+#include "DNA_scene_types.h"
+
 #include "BKE_action.h"
+#include "BKE_deform.h"
+#include "BKE_editmesh.h"
 #include "BKE_object_deform.h"  /* own include */
 #include "BKE_object.h"
 #include "BKE_modifier.h"
 
-#include "DNA_armature_types.h"
-#include "DNA_modifier_types.h"
-#include "DNA_object_types.h"
+/** \name Misc helpers
+ * \{ */
+
+static Lattice *object_defgroup_lattice_get(ID *id)
+{
+       Lattice *lt = (Lattice *)id;
+       BLI_assert(GS(id->name) == ID_LT);
+       return (lt->editlatt) ? lt->editlatt->latt : lt;
+}
+
+/**
+ * Update users of vgroups from this object, according to given map.
+ *
+ * Use it when you remove or reorder vgroups in the object.
+ *
+ * \param map an array mapping old indices to new indices.
+ */
+void BKE_object_defgroup_remap_update_users(Object *ob, int *map)
+{
+       ModifierData *md;
+       ParticleSystem *psys;
+       int a;
+
+       /* these cases don't use names to refer to vertex groups, so when
+        * they get removed the numbers get out of sync, this corrects that */
+
+       if (ob->soft) {
+               ob->soft->vertgroup = map[ob->soft->vertgroup];
+       }
+
+       for (md = ob->modifiers.first; md; md = md->next) {
+               if (md->type == eModifierType_Explode) {
+                       ExplodeModifierData *emd = (ExplodeModifierData *)md;
+                       emd->vgroup = map[emd->vgroup];
+               }
+               else if (md->type == eModifierType_Cloth) {
+                       ClothModifierData *clmd = (ClothModifierData *)md;
+                       ClothSimSettings *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];
+                       }
+               }
+       }
+
+       for (psys = ob->particlesystem.first; psys; psys = psys->next) {
+               for (a = 0; a < PSYS_TOT_VG; a++) {
+                       psys->vgroup[a] = map[psys->vgroup[a]];
+               }
+       }
+}
+/** \} */
+
+
+/** \name Group creation
+ * \{ */
+
+/**
+ * Add a vgroup of given name to object. *Does not* handle MDeformVert data at all!
+ */
+bDeformGroup *BKE_object_defgroup_add_name(Object *ob, const char *name)
+{
+       bDeformGroup *defgroup;
+
+       if (!ob || !OB_TYPE_SUPPORT_VGROUP(ob->type))
+               return NULL;
+
+       defgroup = BKE_defgroup_new(ob, name);
+
+       ob->actdef = BLI_listbase_count(&ob->defbase);
+
+       return defgroup;
+}
+
+/**
+ * Add a vgroup of default name to object. *Does not* handle MDeformVert data at all!
+ */
+bDeformGroup *BKE_object_defgroup_add(Object *ob) 
+{
+       return BKE_object_defgroup_add_name(ob, DATA_("Group"));
+}
+
+/**
+ * Create MDeformVert data for given ID. Work in Object mode only.
+ */
+MDeformVert *BKE_object_defgroup_data_create(ID *id)
+{
+       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 me->dvert;
+       }
+       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 lt->dvert;
+       }
+
+       return NULL;
+}
+/** \} */
+
+
+/** \name Group clearing
+ * \{ */
+
+/**
+ * Remove all verts (or only selected ones) from given vgroup. Work in Object and Edit modes.
+ *
+ * \param allverts If true, remove all vertices, else only selected ones.
+ * \return True if any vertex was removed, false otherwise.
+ */
+bool BKE_object_defgroup_clear(Object *ob, bDeformGroup *dg, const bool use_selection)
+{
+       MDeformVert *dv;
+       const int def_nr = BLI_findindex(&ob->defbase, dg);
+       bool changed = false;
+
+       if (ob->type == OB_MESH) {
+               Mesh *me = ob->data;
+
+               if (me->edit_btmesh) {
+                       BMEditMesh *em = me->edit_btmesh;
+                       const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT);
+
+                       if (cd_dvert_offset != -1) {
+                               BMVert *eve;
+                               BMIter iter;
+
+                               BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
+                                       dv = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset);
+
+                                       if (dv && dv->dw && (!use_selection || BM_elem_flag_test(eve, BM_ELEM_SELECT))) {
+                                               MDeformWeight *dw = defvert_find_index(dv, def_nr);
+                                               defvert_remove_group(dv, dw); /* dw can be NULL */
+                                               changed = true;
+                                       }
+                               }
+                       }
+               }
+               else {
+                       if (me->dvert) {
+                               MVert *mv;
+                               int i;
+
+                               mv = me->mvert;
+                               dv = me->dvert;
+
+                               for (i = 0; i < me->totvert; i++, mv++, dv++) {
+                                       if (mv->flag & SELECT) {
+                                               if (dv->dw && (!use_selection || (mv->flag & SELECT))) {
+                                                       MDeformWeight *dw = defvert_find_index(dv, def_nr);
+                                                       defvert_remove_group(dv, dw);  /* dw can be NULL */
+                                                       changed = true;
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+       else if (ob->type == OB_LATTICE) {
+               Lattice *lt = object_defgroup_lattice_get((ID *)(ob->data));
+
+               if (lt->dvert) {
+                       BPoint *bp;
+                       int i, tot = lt->pntsu * lt->pntsv * lt->pntsw;
+
+                       for (i = 0, bp = lt->def; i < tot; i++, bp++) {
+                               if (!use_selection || (bp->f1 & SELECT)) {
+                                       MDeformWeight *dw;
+
+                                       dv = &lt->dvert[i];
+
+                                       dw = defvert_find_index(dv, def_nr);
+                                       defvert_remove_group(dv, dw);  /* dw can be NULL */
+                                       changed = true;
+                               }
+                       }
+               }
+       }
+
+       return changed;
+}
+
+/**
+ * Remove all verts (or only selected ones) from all vgroups. Work in Object and Edit modes.
+ *
+ * \param allverts If true, remove all vertices, else only selected ones.
+ * \return True if any vertex was removed, false otherwise.
+ */
+bool BKE_object_defgroup_clear_all(Object *ob, const bool use_selection)
+{
+       bDeformGroup *dg;
+       bool changed = false;
+
+       for (dg = ob->defbase.first; dg; dg = dg->next) {
+               if (BKE_object_defgroup_clear(ob, dg, use_selection)) {
+                       changed = true;
+               }
+       }
+
+       return changed;
+}
+/** \} */
+
+
+/** \name Group removal
+ * \{ */
+
+static void object_defgroup_remove_update_users(Object *ob, const int idx)
+{
+       int i, defbase_tot = BLI_listbase_count(&ob->defbase) + 1;
+       int *map = MEM_mallocN(sizeof(int) * defbase_tot, "vgroup del");
+
+       map[idx] = map[0] = 0;
+       for (i = 1; i < idx; i++) {
+               map[i] = i;
+       }
+       for (i = idx + 1; i < defbase_tot; i++) {
+               map[i] = i - 1;
+       }
+
+       BKE_object_defgroup_remap_update_users(ob, map);
+       MEM_freeN(map);
+}
+
+static void object_defgroup_remove_common(Object *ob, bDeformGroup *dg, const int def_nr)
+{
+       object_defgroup_remove_update_users(ob, def_nr + 1);
+
+       /* Remove the group */
+       BLI_freelinkN(&ob->defbase, dg);
+
+       /* Update the active deform index if necessary */
+       if (ob->actdef > def_nr)
+               ob->actdef--;
+
+       /* remove all dverts */
+       if (BLI_listbase_is_empty(&ob->defbase)) {
+               if (ob->type == OB_MESH) {
+                       Mesh *me = ob->data;
+                       CustomData_free_layer_active(&me->vdata, CD_MDEFORMVERT, me->totvert);
+                       me->dvert = NULL;
+               }
+               else if (ob->type == OB_LATTICE) {
+                       Lattice *lt = object_defgroup_lattice_get((ID *)(ob->data));
+                       if (lt->dvert) {
+                               MEM_freeN(lt->dvert);
+                               lt->dvert = NULL;
+                       }
+               }
+       }
+       else if (ob->actdef < 1) {  /* Keep a valid active index if we still have some vgroups. */
+               ob->actdef = 1;
+       }
+}
+
+static void object_defgroup_remove_object_mode(Object *ob, bDeformGroup *dg)
+{
+       MDeformVert *dvert_array = NULL;
+       int dvert_tot = 0;
+       const int def_nr = BLI_findindex(&ob->defbase, dg);
+
+       BLI_assert(def_nr != -1);
+
+       BKE_object_defgroup_array_get(ob->data, &dvert_array, &dvert_tot);
+
+       if (dvert_array) {
+               int i, j;
+               MDeformVert *dv;
+               for (i = 0, dv = dvert_array; i < dvert_tot; i++, dv++) {
+                       MDeformWeight *dw;
+
+                       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 */
+                       for (j = 0; j < dv->totweight; j++) {
+                               if (dv->dw[j].def_nr > def_nr) {
+                                       dv->dw[j].def_nr--;
+                               }
+                       }
+                       /* done */
+               }
+       }
+
+       object_defgroup_remove_common(ob, dg, def_nr);
+}
+
+static void object_defgroup_remove_edit_mode(Object *ob, bDeformGroup *dg)
+{
+       int i;
+       const int def_nr = BLI_findindex(&ob->defbase, dg);
+
+       BLI_assert(def_nr != -1);
+
+       /* Make sure that no verts are using this group - if none were removed, we can skip next per-vert update. */
+       if (!BKE_object_defgroup_clear(ob, dg, false)) {
+               /* Nothing to do. */
+       }
+       /* Else, make sure that any groups with higher indices are adjusted accordingly */
+       else if (ob->type == OB_MESH) {
+               Mesh *me = ob->data;
+               BMEditMesh *em = me->edit_btmesh;
+               const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT);
+
+               BMIter iter;
+               BMVert *eve;
+               MDeformVert *dvert;
+
+               BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
+                       dvert = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset);
+
+                       if (dvert) {
+                               for (i = 0; i < dvert->totweight; i++) {
+                                       if (dvert->dw[i].def_nr > def_nr) {
+                                               dvert->dw[i].def_nr--;
+                                       }
+                               }
+                       }
+               }
+       }
+       else if (ob->type == OB_LATTICE) {
+               Lattice *lt = ((Lattice *)(ob->data))->editlatt->latt;
+               BPoint *bp;
+               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++) {
+                                       if (dvert->dw[i].def_nr > def_nr) {
+                                               dvert->dw[i].def_nr--;
+                                       }
+                               }
+                       }
+               }
+       }
+
+       object_defgroup_remove_common(ob, dg, def_nr);
+}
+
+/**
+ * Remove given vgroup from object. Work in Object and Edit modes.
+ */
+void BKE_object_defgroup_remove(Object *ob, bDeformGroup *defgroup)
+{
+       if (BKE_object_is_in_editmode_vgroup(ob))
+               object_defgroup_remove_edit_mode(ob, defgroup);
+       else
+               object_defgroup_remove_object_mode(ob, defgroup);
+}
+
+/**
+ * Remove all vgroups from object. Work in Object and Edit modes.
+ */
+void BKE_object_defgroup_remove_all(Object *ob)
+{
+       bDeformGroup *dg = (bDeformGroup *)ob->defbase.first;
+       const bool edit_mode = BKE_object_is_in_editmode_vgroup(ob);
+
+       if (dg) {
+               while (dg) {
+                       bDeformGroup *next_dg = dg->next;
+
+                       if (edit_mode)
+                               object_defgroup_remove_edit_mode(ob, dg);
+                       else
+                               object_defgroup_remove_object_mode(ob, dg);
+
+                       dg = next_dg;
+               }
+       }
+       else {  /* ob->defbase is empty... */
+               /* remove all dverts */
+               if (ob->type == OB_MESH) {
+                       Mesh *me = ob->data;
+                       CustomData_free_layer_active(&me->vdata, CD_MDEFORMVERT, me->totvert);
+                       me->dvert = NULL;
+               }
+               else if (ob->type == OB_LATTICE) {
+                       Lattice *lt = object_defgroup_lattice_get((ID *)(ob->data));
+                       if (lt->dvert) {
+                               MEM_freeN(lt->dvert);
+                               lt->dvert = NULL;
+                       }
+               }
+               /* Fix counters/indices */
+               ob->actdef = 0;
+       }
+}
+
+/**
+ * Get MDeformVert vgroup data from given object. Should only be used in Object mode.
+ *
+ * \return True if the id type supports weights.
+ */
+bool BKE_object_defgroup_array_get(ID *id, MDeformVert **dvert_arr, int *dvert_tot)
+{
+       if (id) {
+               switch (GS(id->name)) {
+                       case ID_ME:
+                       {
+                               Mesh *me = (Mesh *)id;
+                               *dvert_arr = me->dvert;
+                               *dvert_tot = me->totvert;
+                               return true;
+                       }
+                       case ID_LT:
+                       {
+                               Lattice *lt = object_defgroup_lattice_get(id);
+                               *dvert_arr = lt->dvert;
+                               *dvert_tot = lt->pntsu * lt->pntsv * lt->pntsw;
+                               return true;
+                       }
+               }
+       }
+
+       *dvert_arr = NULL;
+       *dvert_tot = 0;
+       return false;
+}
+/** \} */
 
 /* --- functions for getting vgroup aligned maps --- */
 
  * gets the status of "flag" for each bDeformGroup
  * in ob->defbase and returns an array containing them
  */
-bool *BKE_objdef_lock_flags_get(Object *ob, const int defbase_tot)
+bool *BKE_object_defgroup_lock_flags_get(Object *ob, const int defbase_tot)
 {
        bool is_locked = false;
        int i;
@@ -66,11 +505,11 @@ bool *BKE_objdef_lock_flags_get(Object *ob, const int defbase_tot)
        return NULL;
 }
 
-bool *BKE_objdef_validmap_get(Object *ob, const int defbase_tot)
+bool *BKE_object_defgroup_validmap_get(Object *ob, const int defbase_tot)
 {
        bDeformGroup *dg;
        ModifierData *md;
-       bool *vgroup_validmap;
+       bool *defgroup_validmap;
        GHash *gh;
        int i, step1 = 1;
        //int defbase_tot = BLI_listbase_count(&ob->defbase);
@@ -80,7 +519,7 @@ bool *BKE_objdef_validmap_get(Object *ob, const int defbase_tot)
                return NULL;
        }
 
-       gh = BLI_ghash_str_new_ex("BKE_objdef_validmap_get gh", defbase_tot);
+       gh = BLI_ghash_str_new_ex(__func__, defbase_tot);
 
        /* add all names to a hash table */
        for (dg = ob->defbase.first; dg; dg = dg->next) {
@@ -115,23 +554,23 @@ bool *BKE_objdef_validmap_get(Object *ob, const int defbase_tot)
                }
        }
 
-       vgroup_validmap = MEM_mallocN(sizeof(*vgroup_validmap) * defbase_tot, "wpaint valid map");
+       defgroup_validmap = MEM_mallocN(sizeof(*defgroup_validmap) * defbase_tot, "wpaint valid map");
 
        /* add all names to a hash table */
        for (dg = ob->defbase.first, i = 0; dg; dg = dg->next, i++) {
-               vgroup_validmap[i] = (BLI_ghash_lookup(gh, dg->name) != NULL);
+               defgroup_validmap[i] = (BLI_ghash_lookup(gh, dg->name) != NULL);
        }
 
        BLI_assert(i == BLI_ghash_size(gh));
 
        BLI_ghash_free(gh, NULL, NULL);
 
-       return vgroup_validmap;
+       return defgroup_validmap;
 }
 
 /* Returns total selected vgroups,
  * wpi.defbase_sel is assumed malloc'd, all values are set */
-bool *BKE_objdef_selected_get(Object *ob, int defbase_tot, int *r_dg_flags_sel_tot)
+bool *BKE_object_defgroup_selected_get(Object *ob, int defbase_tot, int *r_dg_flags_sel_tot)
 {
        bool *dg_selection = MEM_mallocN(defbase_tot * sizeof(bool), __func__);
        bDeformGroup *defgroup;
@@ -158,3 +597,86 @@ bool *BKE_objdef_selected_get(Object *ob, int defbase_tot, int *r_dg_flags_sel_t
 
        return dg_selection;
 }
+
+
+/**
+ * Return the subset type of the Vertex Group Selection
+ */
+bool *BKE_object_defgroup_subset_from_select_type(
+        Object *ob, eVGroupSelect subset_type, int *r_defgroup_tot, int *r_subset_count)
+{
+       bool *defgroup_validmap = NULL;
+       *r_defgroup_tot = BLI_listbase_count(&ob->defbase);
+
+       switch (subset_type) {
+               case WT_VGROUP_ACTIVE:
+               {
+                       const int def_nr_active = ob->actdef - 1;
+                       defgroup_validmap = MEM_mallocN(*r_defgroup_tot * sizeof(*defgroup_validmap), __func__);
+                       memset(defgroup_validmap, false, *r_defgroup_tot * sizeof(*defgroup_validmap));
+                       if ((def_nr_active >= 0) && (def_nr_active < *r_defgroup_tot)) {
+                               *r_subset_count = 1;
+                               defgroup_validmap[def_nr_active] = true;
+                       }
+                       else {
+                               *r_subset_count = 0;
+                       }
+                       break;
+               }
+               case WT_VGROUP_BONE_SELECT:
+               {
+                       defgroup_validmap = BKE_object_defgroup_selected_get(ob, *r_defgroup_tot, r_subset_count);
+                       break;
+               }
+               case WT_VGROUP_BONE_DEFORM:
+               {
+                       int i;
+                       defgroup_validmap = BKE_object_defgroup_validmap_get(ob, *r_defgroup_tot);
+                       *r_subset_count = 0;
+                       for (i = 0; i < *r_defgroup_tot; i++) {
+                               if (defgroup_validmap[i] == true) {
+                                       *r_subset_count += 1;
+                               }
+                       }
+                       break;
+               }
+               case WT_VGROUP_BONE_DEFORM_OFF:
+               {
+                       int i;
+                       defgroup_validmap = BKE_object_defgroup_validmap_get(ob, *r_defgroup_tot);
+                       *r_subset_count = 0;
+                       for (i = 0; i < *r_defgroup_tot; i++) {
+                               defgroup_validmap[i] = !defgroup_validmap[i];
+                               if (defgroup_validmap[i] == true) {
+                                       *r_subset_count += 1;
+                               }
+                       }
+                       break;
+               }
+               case WT_VGROUP_ALL:
+               default:
+               {
+                       defgroup_validmap = MEM_mallocN(*r_defgroup_tot * sizeof(*defgroup_validmap), __func__);
+                       memset(defgroup_validmap, true, *r_defgroup_tot * sizeof(*defgroup_validmap));
+                       *r_subset_count = *r_defgroup_tot;
+                       break;
+               }
+       }
+
+       return defgroup_validmap;
+}
+
+/**
+ * store indices from the defgroup_validmap (faster lookups in some cases)
+ */
+void BKE_object_defgroup_subset_to_index_array(
+        const bool *defgroup_validmap, const int defgroup_tot, int *r_defgroup_subset_map)
+{
+       int i, j = 0;
+       for (i = 0; i < defgroup_tot; i++) {
+               if (defgroup_validmap[i]) {
+                       r_defgroup_subset_map[j++] = i;
+               }
+       }
+}
+
index 75928f9d189618fb524d2bcd61020b36c19cf1da..71875d6274a19091d9162a500e92b4ed45a042b4 100644 (file)
 #include "BLI_math.h"
 #include "BLI_compiler_attrs.h"
 
-#include "BKE_object.h"
 #include "DNA_armature_types.h"
 #include "DNA_modifier_types.h"
 #include "DNA_scene_types.h"
+
+#include "BKE_action.h"
+#include "BKE_object.h"
+#include "BKE_object_deform.h"
+
 #include "ED_mesh.h"
 #include "ED_object.h"
-#include "BKE_action.h"
 
 #include "SkinInfo.h"
 #include "collada_utils.h"
@@ -263,7 +266,7 @@ void SkinInfo::link_armature(bContext *C, Object *ob, std::map<COLLADAFW::Unique
                        name = bc_get_joint_name(joint_by_uid[(*it).joint_uid]);
                }
 
-               ED_vgroup_add_name(ob, (char *)name);
+               BKE_object_defgroup_add_name(ob, name);
        }
 
        // <vcount> - number of joints per vertex - joints_per_vertex
index 15f75ada0606eab8f42bd5d5a891f85b7c185a6c..3dec7ea48f6ecf14363146bd411fae30132f77c4 100644 (file)
@@ -43,6 +43,7 @@
 #include "BKE_action.h"
 #include "BKE_armature.h"
 #include "BKE_deform.h"
+#include "BKE_object_deform.h"
 #include "BKE_report.h"
 #include "BKE_subsurf.h"
 #include "BKE_modifier.h"
@@ -117,7 +118,7 @@ static int vgroup_add_unique_bone_cb(Object *ob, Bone *bone, void *UNUSED(ptr))
         */
        if (!(bone->flag & BONE_NO_DEFORM)) {
                if (!defgroup_find_name(ob, bone->name)) {
-                       ED_vgroup_add_name(ob, bone->name);
+                       BKE_object_defgroup_add_name(ob, bone->name);
                        return 1;
                }
        }
@@ -164,7 +165,7 @@ static int dgroup_skinnable_cb(Object *ob, Bone *bone, void *datap)
                        
                        if (!wpmode || ((arm->layer & bone->layer) && (bone->flag & BONE_SELECTED)))
                                if (!(defgroup = defgroup_find_name(ob, bone->name)))
-                                       defgroup = ED_vgroup_add_name(ob, bone->name);
+                                       defgroup = BKE_object_defgroup_add_name(ob, bone->name);
                        
                        if (data->list != NULL) {
                                hgroup = (bDeformGroup ***) &data->list;
@@ -276,7 +277,7 @@ static void add_verts_to_dgroups(ReportList *reports, Scene *scene, Object *ob,
        if (numbones == 0)
                return;
        
-       if (ED_vgroup_data_create(ob->data) == false)
+       if (BKE_object_defgroup_data_create(ob->data) == false)
                return;
 
        /* create an array of pointer to bones that are skinnable
index 63362b0638b538facca6672242d4499869bb1d59..8eb7fdf0c409c496ff762dfaad854ebe0d0359d8 100644 (file)
@@ -220,14 +220,8 @@ void ED_mesh_mirrtopo_free(MirrTopoStore_t *mesh_topo_store);
 #define WEIGHT_SUBTRACT 3
 
 bool                 ED_vgroup_sync_from_pose(struct Object *ob);
-struct bDeformGroup *ED_vgroup_add(struct Object *ob);
-struct bDeformGroup *ED_vgroup_add_name(struct Object *ob, const char *name);
-void                 ED_vgroup_delete(struct Object *ob, struct bDeformGroup *defgroup);
-void                 ED_vgroup_clear(struct Object *ob);
 void                 ED_vgroup_select_by_name(struct Object *ob, const char *name);
-bool                 ED_vgroup_data_create(struct ID *id);
 void                 ED_vgroup_data_clamp_range(struct ID *id, const int total);
-bool                 ED_vgroup_array_get(struct ID *id, struct MDeformVert **dvert_arr, int *dvert_tot);
 bool                 ED_vgroup_array_copy(struct Object *ob, struct Object *ob_from);
 bool                 ED_vgroup_parray_alloc(struct ID *id, struct MDeformVert ***dvert_arr, int *dvert_tot,
                                             const bool use_vert_sel);
index 39586039e8fa9beb73fac34fd1bfa4238b05709a..900da3ee07c6a03666b3a32af56dcbcc72fed120 100644 (file)
@@ -209,12 +209,6 @@ bool ED_object_multires_update_totlevels_cb(struct Object *ob, void *totlevel_v)
 /* object_select.c */
 void ED_object_select_linked_by_id(struct bContext *C, struct ID *id);
 
-
-bool *ED_vgroup_subset_from_select_type(struct Object *ob, enum eVGroupSelect subset_type,
-                                        int *r_vgroup_tot, int *r_subset_count);
-void ED_vgroup_subset_to_index_array(const bool *vgroup_validmap, const int vgroup_tot,
-                                     int *r_vgroup_subset_map);
-
 struct EnumPropertyItem *ED_object_vgroup_selection_itemf_helper(
         const struct bContext *C,
         struct PointerRNA *ptr,
index cec5c683221017bfe2da58505f4b93f7c4474fa5..7ef8bb13de3fea6f1c2db6bf67f66b57d8fd4211 100644 (file)
@@ -68,6 +68,7 @@
 #include "BKE_multires.h"
 #include "BKE_report.h"
 #include "BKE_object.h"
+#include "BKE_object_deform.h"
 #include "BKE_ocean.h"
 #include "BKE_paint.h"
 #include "BKE_particle.h"
@@ -1667,7 +1668,7 @@ static void skin_armature_bone_create(Object *skin_ob,
                BLI_snprintf(bone->name, sizeof(bone->name), "Bone.%.2d", endx);
 
                /* add bDeformGroup */
-               if ((dg = ED_vgroup_add_name(skin_ob, bone->name))) {
+               if ((dg = BKE_object_defgroup_add_name(skin_ob, bone->name))) {
                        ED_vgroup_vert_add(skin_ob, dg, parent_v, 1, WEIGHT_REPLACE);
                        ED_vgroup_vert_add(skin_ob, dg, v, 1, WEIGHT_REPLACE);
                }
index 672dcb47d920dea68d5f45ef03fe9874aeb3765b..3fb0132f81bb623e0008d4f1a294a1375e7742b3 100644 (file)
 #include "object_intern.h"
 
 /************************ Exported Functions **********************/
-static void vgroup_remap_update_users(Object *ob, int *map);
-static void vgroup_delete_edit_mode(Object *ob, bDeformGroup *defgroup);
-static void vgroup_delete_object_mode(Object *ob, bDeformGroup *dg);
-static void vgroup_delete_all(Object *ob);
-
 static bool vertex_group_use_vert_sel(Object *ob)
 {
        if (ob->mode == OB_MODE_EDIT) {
@@ -126,71 +121,6 @@ bool ED_vgroup_sync_from_pose(Object *ob)
        return false;
 }
 
-bDeformGroup *ED_vgroup_add_name(Object *ob, const char *name)
-{
-       bDeformGroup *defgroup;
-
-       if (!ob || !OB_TYPE_SUPPORT_VGROUP(ob->type))
-               return NULL;
-
-       defgroup = BKE_defgroup_new(ob, name);
-
-       ob->actdef = BLI_listbase_count(&ob->defbase);
-
-       return defgroup;
-}
-
-bDeformGroup *ED_vgroup_add(Object *ob) 
-{
-       return ED_vgroup_add_name(ob, DATA_("Group"));
-}
-
-void ED_vgroup_delete(Object *ob, bDeformGroup *defgroup) 
-{
-       BLI_assert(BLI_findindex(&ob->defbase, defgroup) != -1);
-
-       if (BKE_object_is_in_editmode_vgroup(ob))
-               vgroup_delete_edit_mode(ob, defgroup);
-       else
-               vgroup_delete_object_mode(ob, defgroup);
-}
-
-void ED_vgroup_clear(Object *ob)
-{
-       bDeformGroup *dg = (bDeformGroup *)ob->defbase.first;
-       int edit_mode = BKE_object_is_in_editmode_vgroup(ob);
-
-       while (dg) {
-               bDeformGroup *next_dg = dg->next;
-
-               if (edit_mode)
-                       vgroup_delete_edit_mode(ob, dg);
-               else
-                       vgroup_delete_object_mode(ob, dg);
-
-               dg = next_dg;
-       }
-}
-
-bool 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);
-               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");
-               return true;
-       }
-       else {
-               return false;
-       }
-}
-
 /**
  * Removes out of range MDeformWeights
  */
@@ -455,34 +385,6 @@ void ED_vgroup_parray_remove_zero(MDeformVert **dvert_array, const int dvert_tot
        }
 }
 
-/* returns true if the id type supports weights */
-bool ED_vgroup_array_get(ID *id, MDeformVert **dvert_arr, int *dvert_tot)
-{
-       if (id) {
-               switch (GS(id->name)) {
-                       case ID_ME:
-                       {
-                               Mesh *me = (Mesh *)id;
-                               *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;
-                               return true;
-                       }
-               }
-       }
-
-       *dvert_arr = NULL;
-       *dvert_tot = 0;
-       return false;
-}
-
 /* matching index only */
 bool ED_vgroup_array_copy(Object *ob, Object *ob_from)
 {
@@ -501,7 +403,7 @@ bool ED_vgroup_array_copy(Object *ob, Object *ob_from)
        ED_vgroup_parray_alloc(ob_from->data, &dvert_array_from, &dvert_tot_from, false);
        ED_vgroup_parray_alloc(ob->data, &dvert_array, &dvert_tot, false);
 
-       if ((dvert_array == NULL) && (dvert_array_from != NULL) && ED_vgroup_data_create(ob->data)) {
+       if ((dvert_array == NULL) && (dvert_array_from != NULL) && BKE_object_defgroup_data_create(ob->data)) {
                ED_vgroup_parray_alloc(ob->data, &dvert_array, &dvert_tot, false);
                new_vgroup = true;
        }
@@ -513,7 +415,7 @@ bool ED_vgroup_array_copy(Object *ob, Object *ob_from)
 
                if (new_vgroup == true) {
                        /* free the newly added vgroup since it wasn't compatible */
-                       vgroup_delete_all(ob);
+                       BKE_object_defgroup_remove_all(ob);
                }
 
                /* if true: both are 0 and nothing needs changing, consider this a success */
@@ -531,7 +433,7 @@ bool ED_vgroup_array_copy(Object *ob, Object *ob_from)
                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);
+               BKE_object_defgroup_remap_update_users(ob, remap);
                MEM_freeN(remap);
        }
 
@@ -672,7 +574,7 @@ static void vgroup_normalize_active(Object *ob, eVGroupSelect subset_type)
                return;
        }
 
-       vgroup_validmap = ED_vgroup_subset_from_select_type(ob, subset_type, &vgroup_tot, &subset_count);
+       vgroup_validmap = BKE_object_defgroup_subset_from_select_type(ob, subset_type, &vgroup_tot, &subset_count);
        defvert_normalize_subset(dvert_act, vgroup_validmap, vgroup_tot);
        MEM_freeN((void *)vgroup_validmap);
 
@@ -693,7 +595,7 @@ static void vgroup_copy_active_to_sel(Object *ob, eVGroupSelect subset_type)
        BMEditMesh *em = me->edit_btmesh;
        MDeformVert *dvert_act;
        int i, vgroup_tot, subset_count;
-       const bool *vgroup_validmap = ED_vgroup_subset_from_select_type(ob, subset_type, &vgroup_tot, &subset_count);
+       const bool *vgroup_validmap = BKE_object_defgroup_subset_from_select_type(ob, subset_type, &vgroup_tot, &subset_count);
 
 
        if (em) {
@@ -915,7 +817,7 @@ static bool ed_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGro
        }
 
        /* Create data in memory when nothing there.*/
-       if (!me_dst->dvert) ED_vgroup_data_create(&me_dst->id);
+       if (!me_dst->dvert) BKE_object_defgroup_data_create(&me_dst->id);
 
        /* Get vertex group for destination mesh */
        ED_vgroup_parray_alloc(&me_dst->id, &dv_array_dst, &dv_tot_dst, use_vert_sel);
@@ -952,7 +854,7 @@ static bool ed_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGro
                            dv_array_src == NULL || dv_array_dst == NULL)
                        {
                                if (is_dg_dst_new) {
-                                       ED_vgroup_delete(ob_dst, dg_dst);
+                                       BKE_object_defgroup_remove(ob_dst, dg_dst);
                                }
 
                                if (dv_array_src) MEM_freeN(dv_array_src);
@@ -1165,7 +1067,7 @@ static void ED_vgroup_nr_vert_add(Object *ob,
        int tot;
 
        /* get the vert */
-       ED_vgroup_array_get(ob->data, &dvert, &tot);
+       BKE_object_defgroup_array_get(ob->data, &dvert, &tot);
        
        if (dvert == NULL)
                return;
@@ -1251,8 +1153,8 @@ void ED_vgroup_vert_add(Object *ob, bDeformGroup *dg, int vertnum, float weight,
 
                /* if there's no deform verts then create some,
                 */
-               if (ED_vgroup_array_get(ob->data, &dv, &tot) && dv == NULL)
-                       ED_vgroup_data_create(ob->data);
+               if (BKE_object_defgroup_array_get(ob->data, &dv, &tot) && dv == NULL)
+                       BKE_object_defgroup_data_create(ob->data);
 
                /* call another function to do the work
                 */
@@ -1277,7 +1179,7 @@ void ED_vgroup_vert_remove(Object *ob, bDeformGroup *dg, int vertnum)
                /* get the deform vertices corresponding to the
                 * vertnum
                 */
-               ED_vgroup_array_get(ob->data, &dvert, &tot);
+               BKE_object_defgroup_array_get(ob->data, &dvert, &tot);
 
                if (dvert) {
                        MDeformVert *dv = &dvert[vertnum];
@@ -1488,86 +1390,6 @@ static void vgroup_duplicate(Object *ob)
        }
 }
 
-/**
- * Return the subset type of the Vertex Group Selection
- */
-bool *ED_vgroup_subset_from_select_type(Object *ob, eVGroupSelect subset_type, int *r_vgroup_tot, int *r_subset_count)
-{
-       bool *vgroup_validmap = NULL;
-       *r_vgroup_tot = BLI_listbase_count(&ob->defbase);
-
-       switch (subset_type) {
-               case WT_VGROUP_ACTIVE:
-               {
-                       const int def_nr_active = ob->actdef - 1;
-                       vgroup_validmap = MEM_mallocN(*r_vgroup_tot * sizeof(*vgroup_validmap), __func__);
-                       memset(vgroup_validmap, false, *r_vgroup_tot * sizeof(*vgroup_validmap));
-                       if ((def_nr_active >= 0) && (def_nr_active < *r_vgroup_tot)) {
-                               *r_subset_count = 1;
-                               vgroup_validmap[def_nr_active] = true;
-                       }
-                       else {
-                               *r_subset_count = 0;
-                       }
-                       break;
-               }
-               case WT_VGROUP_BONE_SELECT:
-               {
-                       vgroup_validmap = BKE_objdef_selected_get(ob, *r_vgroup_tot, r_subset_count);
-                       break;
-               }
-               case WT_VGROUP_BONE_DEFORM:
-               {
-                       int i;
-                       vgroup_validmap = BKE_objdef_validmap_get(ob, *r_vgroup_tot);
-                       *r_subset_count = 0;
-                       for (i = 0; i < *r_vgroup_tot; i++) {
-                               if (vgroup_validmap[i] == true) {
-                                       *r_subset_count += 1;
-                               }
-                       }
-                       break;
-               }
-               case WT_VGROUP_BONE_DEFORM_OFF:
-               {
-                       int i;
-                       vgroup_validmap = BKE_objdef_validmap_get(ob, *r_vgroup_tot);
-                       *r_subset_count = 0;
-                       for (i = 0; i < *r_vgroup_tot; i++) {
-                               vgroup_validmap[i] = !vgroup_validmap[i];
-                               if (vgroup_validmap[i] == true) {
-                                       *r_subset_count += 1;
-                               }
-                       }
-                       break;
-               }
-               case WT_VGROUP_ALL:
-               default:
-               {
-                       vgroup_validmap = MEM_mallocN(*r_vgroup_tot * sizeof(*vgroup_validmap), __func__);
-                       memset(vgroup_validmap, true, *r_vgroup_tot * sizeof(*vgroup_validmap));
-                       *r_subset_count = *r_vgroup_tot;
-                       break;
-               }
-       }
-
-       return vgroup_validmap;
-}
-
-/**
- * store indices from the vgroup_validmap (faster lookups in some cases)
- */
-void ED_vgroup_subset_to_index_array(const bool *vgroup_validmap, const int vgroup_tot,
-                                     int *r_vgroup_subset_map)
-{
-       int i, j = 0;
-       for (i = 0; i < vgroup_tot; i++) {
-               if (vgroup_validmap[i]) {
-                       r_vgroup_subset_map[j++] = i;
-               }
-       }
-}
-
 static void vgroup_normalize(Object *ob)
 {
        MDeformWeight *dw;
@@ -2042,7 +1864,7 @@ static void vgroup_normalize_all(Object *ob,
 
        if (dvert_array) {
                const int defbase_tot = BLI_listbase_count(&ob->defbase);
-               bool *lock_flags = BKE_objdef_lock_flags_get(ob, defbase_tot);
+               bool *lock_flags = BKE_object_defgroup_lock_flags_get(ob, defbase_tot);
 
                if ((lock_active == true) &&
                    (lock_flags != NULL) &&
@@ -2195,7 +2017,7 @@ static void vgroup_blend_subset(Object *ob, const bool *vgroup_validmap, const i
 
        BLI_SMALLSTACK_DECLARE(dv_stack, MDeformVert *);
 
-       ED_vgroup_subset_to_index_array(vgroup_validmap, vgroup_tot, vgroup_subset_map);
+       BKE_object_defgroup_subset_to_index_array(vgroup_validmap, vgroup_tot, vgroup_subset_map);
        ED_vgroup_parray_alloc(ob->data, &dvert_array, &dvert_tot, false);
        memset(vgroup_subset_weights, 0, sizeof(*vgroup_subset_weights) * subset_count);
 
@@ -2715,298 +2537,13 @@ cleanup:
 
 }
 
-static void vgroup_remap_update_users(Object *ob, int *map)
-{
-       ExplodeModifierData *emd;
-       ModifierData *md;
-       ParticleSystem *psys;
-       ClothModifierData *clmd;
-       ClothSimSettings *clsim;
-       int a;
-
-       /* these cases don't use names to refer to vertex groups, so when
-        * they get deleted the numbers get out of sync, this corrects that */
-
-       if (ob->soft)
-               ob->soft->vertgroup = map[ob->soft->vertgroup];
-
-       for (md = ob->modifiers.first; md; md = md->next) {
-               if (md->type == eModifierType_Explode) {
-                       emd = (ExplodeModifierData *)md;
-                       emd->vgroup = map[emd->vgroup];
-               }
-               else if (md->type == eModifierType_Cloth) {
-                       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];
-                       }
-               }
-       }
-
-       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_listbase_count(&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;
-
-       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);
-
-       BLI_assert(def_nr != -1);
-
-       ED_vgroup_array_get(ob->data, &dvert_array, &dvert_tot);
-
-       if (dvert_array) {
-               int i, j;
-               MDeformVert *dv;
-               for (i = 0, dv = dvert_array; i < dvert_tot; i++, dv++) {
-                       MDeformWeight *dw;
-
-                       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 */
-                       for (j = 0; j < dv->totweight; j++) {
-                               if (dv->dw[j].def_nr > def_nr) {
-                                       dv->dw[j].def_nr--;
-                               }
-                       }
-                       /* done */
-               }
-       }
-
-       vgroup_delete_update_users(ob, def_nr + 1);
-
-       /* Remove the group */
-       BLI_freelinkN(&ob->defbase, dg);
-
-       /* Update the active deform index if necessary */
-       if (ob->actdef > def_nr)
-               ob->actdef--;
-       if (ob->actdef < 1 && ob->defbase.first)
-               ob->actdef = 1;
-
-       /* remove all dverts */
-       if (BLI_listbase_is_empty(&ob->defbase)) {
-               if (ob->type == OB_MESH) {
-                       Mesh *me = ob->data;
-                       CustomData_free_layer_active(&me->vdata, CD_MDEFORMVERT, me->totvert);
-                       me->dvert = NULL;
-               }
-               else if (ob->type == OB_LATTICE) {
-                       Lattice *lt = ob->data;
-                       if (lt->dvert) {
-                               MEM_freeN(lt->dvert);
-                               lt->dvert = NULL;
-                       }
-               }
-       }
-}
-
-/* only in editmode */
-/* removes from active defgroup, if allverts==0 only selected vertices */
-static bool vgroup_active_remove_verts(Object *ob, const bool allverts, bDeformGroup *dg)
-{
-       MDeformVert *dv;
-       const int def_nr = BLI_findindex(&ob->defbase, dg);
-       bool changed = false;
-
-       if (ob->type == OB_MESH) {
-               Mesh *me = ob->data;
-
-               if (me->edit_btmesh) {
-                       BMEditMesh *em = me->edit_btmesh;
-                       const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT);
-
-                       if (cd_dvert_offset != -1) {
-                               BMVert *eve;
-                               BMIter iter;
-
-                               BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
-                                       dv = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset);
-
-                                       if (dv && dv->dw && (allverts || BM_elem_flag_test(eve, BM_ELEM_SELECT))) {
-                                               MDeformWeight *dw = defvert_find_index(dv, def_nr);
-                                               defvert_remove_group(dv, dw); /* dw can be NULL */
-                                               changed = true;
-                                       }
-                               }
-                       }
-               }
-               else {
-                       if (me->dvert) {
-                               MVert *mv;
-                               int i;
-
-                               mv = me->mvert;
-                               dv = me->dvert;
-
-                               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);
-                                                       defvert_remove_group(dv, dw); /* dw can be NULL */
-                                                       changed = true;
-                                               }
-                                       }
-                               }
-                       }
-               }
-       }
-       else if (ob->type == OB_LATTICE) {
-               Lattice *lt = vgroup_edit_lattice(ob);
-               
-               if (lt->dvert) {
-                       BPoint *bp;
-                       int i, tot = lt->pntsu * lt->pntsv * lt->pntsw;
-                               
-                       for (i = 0, bp = lt->def; i < tot; i++, bp++) {
-                               if (allverts || (bp->f1 & SELECT)) {
-                                       MDeformWeight *dw;
-
-                                       dv = &lt->dvert[i];
-
-                                       dw = defvert_find_index(dv, def_nr);
-                                       defvert_remove_group(dv, dw); /* dw can be NULL */
-                                       changed = true;
-                               }
-                       }
-               }
-       }
-
-       return changed;
-}
-
-static void vgroup_delete_edit_mode(Object *ob, bDeformGroup *dg)
-{
-       int i;
-       const int dg_index = BLI_findindex(&ob->defbase, dg);
-
-       BLI_assert(dg_index != -1);
-
-       /* Make sure that no verts are using this group */
-       if (vgroup_active_remove_verts(ob, true, dg) == false) {
-               /* do nothing */
-       }
-       /* Make sure that any verts with higher indices are adjusted accordingly */
-       else if (ob->type == OB_MESH) {
-               Mesh *me = ob->data;
-               BMEditMesh *em = me->edit_btmesh;
-               const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT);
-
-               BMIter iter;
-               BMVert *eve;
-               MDeformVert *dvert;
-
-               BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
-                       dvert = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset);
-
-                       if (dvert)
-                               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);
-               BPoint *bp;
-               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++) {
-                                       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);
-
-       /* Update the active deform index if necessary */
-       if (ob->actdef > dg_index)
-               ob->actdef--;
-       if (ob->actdef < 1 && ob->defbase.first)
-               ob->actdef = 1;
-
-       /* remove all dverts */
-       if (BLI_listbase_is_empty(&ob->defbase)) {
-               if (ob->type == OB_MESH) {
-                       Mesh *me = ob->data;
-                       CustomData_free_layer_active(&me->vdata, CD_MDEFORMVERT, me->totvert);
-                       me->dvert = NULL;
-               }
-               else if (ob->type == OB_LATTICE) {
-                       Lattice *lt = vgroup_edit_lattice(ob);
-                       if (lt->dvert) {
-                               MEM_freeN(lt->dvert);
-                               lt->dvert = NULL;
-                       }
-               }
-       }
-}
-
-static void vgroup_delete(Object *ob)
+static void vgroup_delete_active(Object *ob)
 {
        bDeformGroup *dg = BLI_findlink(&ob->defbase, ob->actdef - 1);
        if (!dg)
                return;
 
-       if (BKE_object_is_in_editmode_vgroup(ob))
-               vgroup_delete_edit_mode(ob, dg);
-       else
-               vgroup_delete_object_mode(ob, dg);
-}
-
-static void vgroup_delete_all(Object *ob)
-{
-       /* Remove all DVerts */
-       if (ob->type == OB_MESH) {
-               Mesh *me = ob->data;
-               CustomData_free_layer_active(&me->vdata, CD_MDEFORMVERT, me->totvert);
-               me->dvert = NULL;
-       }
-       else if (ob->type == OB_LATTICE) {
-               Lattice *lt = vgroup_edit_lattice(ob);
-               if (lt->dvert) {
-                       MEM_freeN(lt->dvert);
-                       lt->dvert = NULL;
-               }
-       }
-       
-       /* Remove all DefGroups */
-       BLI_freelistN(&ob->defbase);
-       
-       /* Fix counters/indices */
-       ob->actdef = 0;
+       BKE_object_defgroup_remove(ob, dg);
 }
 
 /* only in editmode */
@@ -3051,7 +2588,7 @@ static void vgroup_assign_verts(Object *ob, const float weight)
                        int i;
 
                        if (!me->dvert) {
-                               ED_vgroup_data_create(&me->id);
+                               BKE_object_defgroup_data_create(&me->id);
                        }
 
                        mv = me->mvert;
@@ -3075,7 +2612,7 @@ static void vgroup_assign_verts(Object *ob, const float weight)
                int a, tot;
 
                if (lt->dvert == NULL)
-                       ED_vgroup_data_create(&lt->id);
+                       BKE_object_defgroup_data_create(&lt->id);
 
                dv = lt->dvert;
 
@@ -3093,22 +2630,6 @@ static void vgroup_assign_verts(Object *ob, const float weight)
        }
 }
 
-/* only in editmode */
-/* removes from all defgroup, if allverts==0 only selected vertices */
-static bool vgroup_remove_verts(Object *ob, int allverts)
-{
-       bool changed = false;
-       /* To prevent code redundancy, we just use vgroup_active_remove_verts, but that
-        * only operates on the active vgroup. So we iterate through all groups, by changing
-        * active group index
-        */
-       bDeformGroup *dg;
-       for (dg = ob->defbase.first; dg; dg = dg->next) {
-               changed |= vgroup_active_remove_verts(ob, allverts, dg);
-       }
-       return changed;
-}
-
 /********************** vertex group operators *********************/
 
 static int vertex_group_poll(bContext *C)
@@ -3216,7 +2737,7 @@ static int vertex_group_add_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *ob = ED_object_context(C);
 
-       ED_vgroup_add(ob);
+       BKE_object_defgroup_add(ob);
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_GEOM | ND_VERTEX_GROUP, ob->data);
        WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
@@ -3244,9 +2765,9 @@ static int vertex_group_remove_exec(bContext *C, wmOperator *op)
        Object *ob = ED_object_context(C);
 
        if (RNA_boolean_get(op->ptr, "all"))
-               vgroup_delete_all(ob);
+               BKE_object_defgroup_remove_all(ob);
        else
-               vgroup_delete(ob);
+               vgroup_delete_active(ob);
 
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_GEOM | ND_VERTEX_GROUP, ob->data);
@@ -3311,7 +2832,7 @@ static int vertex_group_assign_new_exec(bContext *C, wmOperator *op)
 {
        /* create new group... */
        Object *ob = ED_object_context(C);
-       ED_vgroup_add(ob);
+       BKE_object_defgroup_add(ob);
        
        /* assign selection to new group */
        return vertex_group_assign_exec(C, op);
@@ -3343,14 +2864,14 @@ static int vertex_group_remove_from_exec(bContext *C, wmOperator *op)
        Object *ob = ED_object_context(C);
 
        if (use_all_groups) {
-               if (vgroup_remove_verts(ob, 0) == false) {
+               if (BKE_object_defgroup_clear_all(ob, true) == false) {
                        return OPERATOR_CANCELLED;
                }
        }
        else {
                bDeformGroup *dg = BLI_findlink(&ob->defbase, ob->actdef - 1);
 
-               if ((dg == NULL) || (vgroup_active_remove_verts(ob, use_all_verts, dg) == false)) {
+               if ((dg == NULL) || (BKE_object_defgroup_clear(ob, dg, !use_all_verts) == false)) {
                        return OPERATOR_CANCELLED;
                }
        }
@@ -3476,7 +2997,7 @@ static int vertex_group_levels_exec(bContext *C, wmOperator *op)
 
        int subset_count, vgroup_tot;
 
-       const bool *vgroup_validmap = ED_vgroup_subset_from_select_type(ob, subset_type, &vgroup_tot, &subset_count);
+       const bool *vgroup_validmap = BKE_object_defgroup_subset_from_select_type(ob, subset_type, &vgroup_tot, &subset_count);
        vgroup_levels_subset(ob, vgroup_validmap, vgroup_tot, subset_count, offset, gain);
        MEM_freeN((void *)vgroup_validmap);
        
@@ -3542,7 +3063,7 @@ static int vertex_group_normalize_all_exec(bContext *C, wmOperator *op)
 
        int subset_count, vgroup_tot;
 
-       const bool *vgroup_validmap = ED_vgroup_subset_from_select_type(ob, subset_type, &vgroup_tot, &subset_count);
+       const bool *vgroup_validmap = BKE_object_defgroup_subset_from_select_type(ob, subset_type, &vgroup_tot, &subset_count);
        vgroup_normalize_all(ob, vgroup_validmap, vgroup_tot, subset_count, lock_active);
        MEM_freeN((void *)vgroup_validmap);
 
@@ -3664,7 +3185,7 @@ static int vertex_group_invert_exec(bContext *C, wmOperator *op)
 
        int subset_count, vgroup_tot;
 
-       const bool *vgroup_validmap = ED_vgroup_subset_from_select_type(ob, subset_type, &vgroup_tot, &subset_count);
+       const bool *vgroup_validmap = BKE_object_defgroup_subset_from_select_type(ob, subset_type, &vgroup_tot, &subset_count);
        vgroup_invert_subset(ob, vgroup_validmap, vgroup_tot, subset_count, auto_assign, auto_remove);
        MEM_freeN((void *)vgroup_validmap);
 
@@ -3705,7 +3226,7 @@ static int vertex_group_blend_exec(bContext *C, wmOperator *op)
 
        int subset_count, vgroup_tot;
 
-       const bool *vgroup_validmap = ED_vgroup_subset_from_select_type(ob, subset_type, &vgroup_tot, &subset_count);
+       const bool *vgroup_validmap = BKE_object_defgroup_subset_from_select_type(ob, subset_type, &vgroup_tot, &subset_count);
        vgroup_blend_subset(ob, vgroup_validmap, vgroup_tot, subset_count, fac);
        MEM_freeN((void *)vgroup_validmap);
 
@@ -3781,7 +3302,7 @@ static int vertex_group_clean_exec(bContext *C, wmOperator *op)
 
        int subset_count, vgroup_tot;
 
-       const bool *vgroup_validmap = ED_vgroup_subset_from_select_type(ob, subset_type, &vgroup_tot, &subset_count);
+       const bool *vgroup_validmap = BKE_object_defgroup_subset_from_select_type(ob, subset_type, &vgroup_tot, &subset_count);
        vgroup_clean_subset(ob, vgroup_validmap, vgroup_tot, subset_count, limit, keep_single);
        MEM_freeN((void *)vgroup_validmap);
 
@@ -3822,7 +3343,7 @@ static int vertex_group_quantize_exec(bContext *C, wmOperator *op)
 
        int subset_count, vgroup_tot;
 
-       const bool *vgroup_validmap = ED_vgroup_subset_from_select_type(ob, subset_type, &vgroup_tot, &subset_count);
+       const bool *vgroup_validmap = BKE_object_defgroup_subset_from_select_type(ob, subset_type, &vgroup_tot, &subset_count);
        vgroup_quantize_subset(ob, vgroup_validmap, vgroup_tot, subset_count, steps);
        MEM_freeN((void *)vgroup_validmap);
 
@@ -3860,7 +3381,7 @@ static int vertex_group_limit_total_exec(bContext *C, wmOperator *op)
 
        int subset_count, vgroup_tot;
 
-       const bool *vgroup_validmap = ED_vgroup_subset_from_select_type(ob, subset_type, &vgroup_tot, &subset_count);
+       const bool *vgroup_validmap = BKE_object_defgroup_subset_from_select_type(ob, subset_type, &vgroup_tot, &subset_count);
        int remove_tot = vgroup_limit_total_subset(ob, vgroup_validmap, vgroup_tot, subset_count, limit);
        MEM_freeN((void *)vgroup_validmap);
 
@@ -4287,7 +3808,7 @@ static int vgroup_do_remap(Object *ob, const char *name_array, wmOperator *op)
        else {
                int dvert_tot = 0;
 
-               ED_vgroup_array_get(ob->data, &dvert, &dvert_tot);
+               BKE_object_defgroup_array_get(ob->data, &dvert, &dvert_tot);
 
                /*create as necessary*/
                if (dvert) {
@@ -4304,7 +3825,7 @@ static int vgroup_do_remap(Object *ob, const char *name_array, wmOperator *op)
                sort_map[i]++;
 
        sort_map_update[0] = 0;
-       vgroup_remap_update_users(ob, sort_map_update);
+       BKE_object_defgroup_remap_update_users(ob, sort_map_update);
 
        BLI_assert(sort_map_update[ob->actdef] >= 0);
        ob->actdef = sort_map_update[ob->actdef];
index 637af5d6536bc539d8d9aa715dca7b49e55e5ef7..d864934171b9e038de2be3eae12c9454da4f53e1 100644 (file)
@@ -40,6 +40,7 @@
 #include "BKE_blender.h"
 #include "BKE_context.h"
 #include "BKE_deform.h"
+#include "BKE_object_deform.h"
 #include "BKE_depsgraph.h"
 #include "BKE_dynamicpaint.h"
 #include "BKE_global.h"
@@ -235,11 +236,11 @@ static int output_toggle_exec(bContext *C, wmOperator *op)
                /* Vertex Weight Layer */
                else if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) {
                        if (!exists) {
-                               ED_vgroup_add_name(ob, name);
+                               BKE_object_defgroup_add_name(ob, name);
                        }
                        else {
                                bDeformGroup *defgroup = defgroup_find_name(ob, name);
-                               if (defgroup) ED_vgroup_delete(ob, defgroup);
+                               if (defgroup) BKE_object_defgroup_remove(ob, defgroup);
                        }
                }
        }
index 75bef040d2e0e0e0e998132c44c818625a9ca786..376d3d3099cf06cae39405e2202edad02d23fa02 100644 (file)
@@ -387,7 +387,7 @@ static int wpaint_mirror_vgroup_ensure(Object *ob, const int vgroup_active)
                }
 
                /* curdef should never be NULL unless this is
-                * a  lamp and ED_vgroup_add_name fails */
+                * a  lamp and BKE_object_defgroup_add_name fails */
                return mirrdef;
        }
 
@@ -2159,7 +2159,7 @@ static bool wpaint_ensure_data(bContext *C, wmOperator *op)
 
        /* if nothing was added yet, we make dverts and a vertex deform group */
        if (!me->dvert) {
-               ED_vgroup_data_create(&me->id);
+               BKE_object_defgroup_data_create(&me->id);
                WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
        }
 
@@ -2174,7 +2174,7 @@ static bool wpaint_ensure_data(bContext *C, wmOperator *op)
                                if (pchan) {
                                        bDeformGroup *dg = defgroup_find_name(ob, pchan->name);
                                        if (dg == NULL) {
-                                               dg = ED_vgroup_add_name(ob, pchan->name);  /* sets actdef */
+                                               dg = BKE_object_defgroup_add_name(ob, pchan->name);  /* sets actdef */
                                        }
                                        else {
                                                int actdef = 1 + BLI_findindex(&ob->defbase, dg);
@@ -2186,7 +2186,7 @@ static bool wpaint_ensure_data(bContext *C, wmOperator *op)
                }
        }
        if (BLI_listbase_is_empty(&ob->defbase)) {
-               ED_vgroup_add(ob);
+               BKE_object_defgroup_add(ob);
        }
 
        /* ensure we don't try paint onto an invalid group */
@@ -2236,9 +2236,9 @@ static bool wpaint_stroke_test_start(bContext *C, wmOperator *op, const float UN
        /* set up auto-normalize, and generate map for detecting which
         * vgroups affect deform bones */
        wpd->defbase_tot = BLI_listbase_count(&ob->defbase);
-       wpd->lock_flags = BKE_objdef_lock_flags_get(ob, wpd->defbase_tot);
+       wpd->lock_flags = BKE_object_defgroup_lock_flags_get(ob, wpd->defbase_tot);
        if (ts->auto_normalize || ts->multipaint || wpd->lock_flags) {
-               wpd->vgroup_validmap = BKE_objdef_validmap_get(ob, wpd->defbase_tot);
+               wpd->vgroup_validmap = BKE_object_defgroup_validmap_get(ob, wpd->defbase_tot);
        }
 
        /* painting on subsurfs should give correct points too, this returns me->totvert amount */
@@ -2318,7 +2318,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
 
        /* *** setup WeightPaintInfo - pass onto do_weight_paint_vertex *** */
        wpi.defbase_tot =        wpd->defbase_tot;
-       wpi.defbase_sel = BKE_objdef_selected_get(ob, wpi.defbase_tot, &wpi.defbase_tot_sel);
+       wpi.defbase_sel = BKE_object_defgroup_selected_get(ob, wpi.defbase_tot, &wpi.defbase_tot_sel);
        if (wpi.defbase_tot_sel == 0 && ob->actdef > 0) {
                wpi.defbase_tot_sel = 1;
        }
index 899be6359ee8b7e4354ceb8f6ecfc4fb9807e120..a58eff3ffff4fadfda4dd796452343af7cf1c321 100644 (file)
@@ -60,6 +60,7 @@
 #include "BKE_editmesh.h"
 #include "BKE_deform.h"
 #include "BKE_object.h"
+#include "BKE_object_deform.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -844,7 +845,7 @@ static void view3d_panel_vgroup(const bContext *C, Panel *pa)
 
                col = uiLayoutColumn(bcol, true);
 
-               vgroup_validmap = ED_vgroup_subset_from_select_type(ob, subset_type, &vgroup_tot, &subset_count);
+               vgroup_validmap = BKE_object_defgroup_subset_from_select_type(ob, subset_type, &vgroup_tot, &subset_count);
                for (i = 0, dg = ob->defbase.first; dg; i++, dg = dg->next) {
                        bool locked = dg->flag & DG_LOCK_WEIGHT;
                        if (vgroup_validmap[i]) {
index e6714bbe433cdcea734662a4a9023d1c4de6f9f5..5f39f0c3d73d397c0357ecb96978ab62dee28b71 100644 (file)
@@ -46,6 +46,8 @@
 #include "BKE_editmesh.h"
 #include "BKE_group.h" /* needed for BKE_group_object_exists() */
 #include "BKE_object.h" /* Needed for BKE_object_matrix_local_get() */
+#include "BKE_object_deform.h"
+
 #include "RNA_access.h"
 #include "RNA_define.h"
 #include "RNA_enum_types.h"
@@ -1389,7 +1391,7 @@ static void rna_Object_boundbox_get(PointerRNA *ptr, float *values)
 
 static bDeformGroup *rna_Object_vgroup_new(Object *ob, const char *name)
 {
-       bDeformGroup *defgroup = ED_vgroup_add_name(ob, name);
+       bDeformGroup *defgroup = BKE_object_defgroup_add_name(ob, name);
 
        WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
 
@@ -1404,7 +1406,7 @@ static void rna_Object_vgroup_remove(Object *ob, ReportList *reports, PointerRNA
                return;
        }
 
-       ED_vgroup_delete(ob, defgroup);
+       BKE_object_defgroup_remove(ob, defgroup);
        RNA_POINTER_INVALIDATE(defgroup_ptr);
 
        WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
@@ -1412,7 +1414,7 @@ static void rna_Object_vgroup_remove(Object *ob, ReportList *reports, PointerRNA
 
 static void rna_Object_vgroup_clear(Object *ob)
 {
-       ED_vgroup_clear(ob);
+       BKE_object_defgroup_remove_all(ob);
 
        WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
 }
index 66af7fa97ddf0f37cab5352a627c7047b9309d78..606409e1cb888b32c47270172e19e57523d25174 100644 (file)
@@ -462,12 +462,9 @@ bool ED_mesh_color_remove_named(struct Mesh *me, const char *name) RET_ZERO
 bool ED_mesh_uv_texture_remove_named(struct Mesh *me, const char *name) RET_ZERO
 void ED_object_constraint_dependency_update(struct Main *bmain, struct Object *ob) RET_NONE
 void ED_object_constraint_update(struct Object *ob) RET_NONE
-struct bDeformGroup *ED_vgroup_add_name(struct Object *ob, const char *name) RET_NULL
 void ED_vgroup_vert_add(struct Object *ob, struct bDeformGroup *dg, int vertnum, float weight, int assignmode) RET_NONE
 void ED_vgroup_vert_remove(struct Object *ob, struct bDeformGroup *dg, int vertnum) RET_NONE
 float ED_vgroup_vert_weight(struct Object *ob, struct bDeformGroup *dg, int vertnum) RET_ZERO
-void ED_vgroup_delete(struct Object *ob, struct bDeformGroup *defgroup) RET_NONE
-void ED_vgroup_clear(struct Object *ob) RET_NONE
 int ED_mesh_mirror_topo_table(struct Object *ob, char mode) RET_ZERO
 int ED_mesh_mirror_spatial_table(struct Object *ob, struct BMEditMesh *em, const float co[3], char mode) RET_ZERO