From f22104542bf0025264934ba235b517abbe562c38 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 9 Feb 2010 22:00:19 +0000 Subject: copy vgroups to selected objects as long as they have aligned arrays. access in the vertex group panel menu. --- source/blender/editors/include/ED_mesh.h | 1 + source/blender/editors/object/object_intern.h | 1 + source/blender/editors/object/object_ops.c | 1 + source/blender/editors/object/object_vgroup.c | 83 ++++++++++++++++++++++++++- 4 files changed, 85 insertions(+), 1 deletion(-) (limited to 'source/blender/editors') diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index 1e0dd78e392..e9cc3faf017 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -190,6 +190,7 @@ struct bDeformGroup *ED_vgroup_add_name(struct Object *ob, char *name); void ED_vgroup_select_by_name(struct Object *ob, char *name); void ED_vgroup_data_create(struct ID *id); 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, int mirror_weights, int flip_vgroups); void ED_vgroup_vert_add(struct Object *ob, struct bDeformGroup *dg, int vertnum, float weight, int assignmode); diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index 0f931e6912d..985132a8ae4 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -184,6 +184,7 @@ void OBJECT_OT_vertex_group_remove_from(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_select(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_deselect(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_copy_to_linked(struct wmOperatorType *ot); +void OBJECT_OT_vertex_group_copy_to_selected(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); diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index 1e71f9bf1d3..16c75e79ba4 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -169,6 +169,7 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_vertex_group_select); WM_operatortype_append(OBJECT_OT_vertex_group_deselect); WM_operatortype_append(OBJECT_OT_vertex_group_copy_to_linked); + WM_operatortype_append(OBJECT_OT_vertex_group_copy_to_selected); 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); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 0c0b48dccc7..70796bd5806 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -75,6 +75,7 @@ #include "object_intern.h" /************************ Exported Functions **********************/ +static void vgroup_remap_update_users(Object *ob, int *map); static Lattice *vgroup_edit_lattice(Object *ob) { @@ -151,6 +152,56 @@ int ED_vgroup_give_array(ID *id, MDeformVert **dvert_arr, int *dvert_tot) *dvert_tot= 0; return FALSE; } + +/* 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 totdef_from= BLI_countlist(&ob_from->defbase); + int totdef= BLI_countlist(&ob->defbase); + + ED_vgroup_give_array(ob_from->data, &dvert_array_from, &dvert_tot_from); + ED_vgroup_give_array(ob->data, &dvert_array, &dvert_tot); + + if(ob==ob_from || dvert_tot==0 || (dvert_tot != dvert_tot_from)) + return 0; + + /* do the copy */ + BLI_freelistN(&ob->defbase); + BLI_duplicatelist(&ob->defbase, &ob_from->defbase); + ob->actdef= ob_from->actdef; + + if(totdef_from < totdef) { + /* correct vgroup indices because the number of vgroups is being reduced. */ + int *remap= MEM_mallocN(sizeof(int) * (totdef + 1), "ED_vgroup_copy_array"); + for(i=0; i<=totdef_from; i++) remap[i]= i; + for(; i<=totdef; i++) remap[i]= 0; /* cany use these, so disable */ + + vgroup_remap_update_users(ob, remap); + MEM_freeN(remap); + } + + dvf= dvert_array_from; + dv= dvert_array; + + for(i=0; idw) + MEM_freeN(dv->dw); + + *dv= *dvf; + + if(dv->dw) + dv->dw= MEM_dupallocN(dv->dw); + } + + return 1; +} + /* for mesh in object mode lattice can be in editmode */ void ED_vgroup_nr_vert_remove(Object *ob, int def_nr, int vertnum) @@ -1758,7 +1809,7 @@ static int vertex_group_copy_to_linked_exec(bContext *C, wmOperator *op) void OBJECT_OT_vertex_group_copy_to_linked(wmOperatorType *ot) { /* identifiers */ - ot->name= "Copy Vertex Group to Linked"; + ot->name= "Copy Vertex Groups to Linked"; ot->idname= "OBJECT_OT_vertex_group_copy_to_linked"; ot->description= "Copy Vertex Groups to all users of the same Geometry data."; @@ -1770,6 +1821,36 @@ void OBJECT_OT_vertex_group_copy_to_linked(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } +static int vertex_group_copy_to_selected_exec(bContext *C, wmOperator *op) +{ + Object *obact= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; + + CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) + { + if(obact != ob) + ED_vgroup_copy_array(ob, obact); + } + CTX_DATA_END; + + return OPERATOR_FINISHED; +} + + +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 indicies."; + + /* api callbacks */ + ot->poll= vertex_group_poll; + ot->exec= vertex_group_copy_to_selected_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + static EnumPropertyItem vgroup_items[]= { {0, NULL, 0, NULL, NULL}}; -- cgit v1.2.3