diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index 4a987d15380..f56bf8d5dfd 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -4997,6 +4997,10 @@ void create_vgroups_from_armature(ReportList *reports, Scene *scene, Object *ob, 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. */ diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index 0c1ee9b36ae..d3de2593b9d 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -227,6 +227,7 @@ void ED_vgroup_delete(struct Object *ob, struct bDeformGroup *de 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); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index f775827c045..a1fb0eb98d2 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -82,6 +82,7 @@ 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 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 @@ int ED_vgroup_data_create(ID *id) } } +/** + * 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;