Revision: 53986
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53986
Author:   campbellbarton
Date:     2013-01-22 10:51:57 +0000 (Tue, 22 Jan 2013)
Log Message:
-----------
fix [#33889] Unexpected weights after parenting with Empty Groups

out of range dvert's are now cleared before adding new-empty groups.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/armature/editarmature.c
    trunk/blender/source/blender/editors/include/ED_mesh.h
    trunk/blender/source/blender/editors/object/object_vgroup.c

Modified: trunk/blender/source/blender/editors/armature/editarmature.c
===================================================================
--- trunk/blender/source/blender/editors/armature/editarmature.c        
2013-01-22 09:37:46 UTC (rev 53985)
+++ trunk/blender/source/blender/editors/armature/editarmature.c        
2013-01-22 10:51:57 UTC (rev 53986)
@@ -4997,6 +4997,10 @@
        bArmature *arm = par->data;
 
        if (mode == ARM_GROUPS_NAME) {
+               /* its possible there are DWeight's outside the range of the 
current
+                * objects deform groups, in this case the new groups wont be 
empty [#33889] */
+               ED_vgroup_data_clamp_range(ob->data, 
BLI_countlist(&ob->defbase));
+
                /* Traverse the bone list, trying to create empty vertex 
                 * groups corresponding to the bone.
                 */

Modified: trunk/blender/source/blender/editors/include/ED_mesh.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_mesh.h      2013-01-22 
09:37:46 UTC (rev 53985)
+++ trunk/blender/source/blender/editors/include/ED_mesh.h      2013-01-22 
10:51:57 UTC (rev 53986)
@@ -227,6 +227,7 @@
 void                 ED_vgroup_clear(struct Object *ob);
 void                 ED_vgroup_select_by_name(struct Object *ob, const char 
*name);
 int                  ED_vgroup_data_create(struct ID *id);
+void                 ED_vgroup_data_clamp_range(struct ID *id, const int 
total);
 int                  ED_vgroup_give_array(struct ID *id, struct MDeformVert 
**dvert_arr, int *dvert_tot);
 int                  ED_vgroup_copy_array(struct Object *ob, struct Object 
*ob_from);
 void                 ED_vgroup_mirror(struct Object *ob, const short 
mirror_weights, const short flip_vgroups, const short all_vgroups);

Modified: trunk/blender/source/blender/editors/object/object_vgroup.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_vgroup.c 2013-01-22 
09:37:46 UTC (rev 53985)
+++ trunk/blender/source/blender/editors/object/object_vgroup.c 2013-01-22 
10:51:57 UTC (rev 53986)
@@ -82,6 +82,7 @@
 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 int ED_vgroup_give_parray(ID *id, MDeformVert ***dvert_arr, int 
*dvert_tot, const short use_vert_sel);
 
 static int vertex_group_use_vert_sel(Object *ob)
 {
@@ -183,6 +184,29 @@
        }
 }
 
+/**
+ * Removes out of range MDeformWeights
+ */
+void ED_vgroup_data_clamp_range(ID *id, const int total)
+{
+       MDeformVert **dvert_arr;
+       int dvert_tot;
+
+       if (ED_vgroup_give_parray(id, &dvert_arr, &dvert_tot, false)) {
+               int i;
+               for (i = 0; i < dvert_tot; i++) {
+                       MDeformVert *dv = dvert_arr[i];
+                       int j;
+                       for (j = 0; j < dv->totweight; j++) {
+                               if (dv->dw[j].def_nr >= total) {
+                                       defvert_remove_group(dv, &dv->dw[j]);
+                                       j--;
+                               }
+                       }
+               }
+       }
+}
+
 static int ED_vgroup_give_parray(ID *id, MDeformVert ***dvert_arr, int 
*dvert_tot, const short use_vert_sel)
 {
        *dvert_tot = 0;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to