diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2010-02-13 04:13:16 +0300 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2010-02-13 04:13:16 +0300 |
commit | 135a944c66c57f11fd77b4f7231686353112e7ac (patch) | |
tree | 3928c457f44f544113e84b3356ab101e3820072e /source/blender/editors/object/object_vgroup.c | |
parent | 1b3948f9aad25fec1923f5ccd36ea525d8e34fb6 (diff) | |
parent | 33b1cbf06d2c822c68676390b1775eb5d78de6e6 (diff) |
Merged changes in the trunk up to revision 26856.
Diffstat (limited to 'source/blender/editors/object/object_vgroup.c')
-rw-r--r-- | source/blender/editors/object/object_vgroup.c | 95 |
1 files changed, 88 insertions, 7 deletions
diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 0c0b48dccc7..626afd1a315 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. * All rights reserved. @@ -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) || dvert_array_from==NULL || dvert_array==NULL) + 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; /* can't use these, so disable */ + + vgroup_remap_update_users(ob, remap); + MEM_freeN(remap); + } + + dvf= dvert_array_from; + dv= dvert_array; + + for(i=0; i<dvert_tot; i++, dvf++, dv++) { + if(dv->dw) + 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) @@ -1681,7 +1732,7 @@ void OBJECT_OT_vertex_group_clean(wmOperatorType *ot) /* identifiers */ ot->name= "Clean Vertex Group"; ot->idname= "OBJECT_OT_vertex_group_clean"; - ot->description= "Remove Vertex Group assignments which aren't required."; + ot->description= "Remove Vertex Group assignments which aren't required"; /* api callbacks */ ot->poll= vertex_group_poll; @@ -1714,7 +1765,7 @@ void OBJECT_OT_vertex_group_mirror(wmOperatorType *ot) /* identifiers */ ot->name= "Mirror Vertex Group"; ot->idname= "OBJECT_OT_vertex_group_mirror"; - ot->description= "Mirror weights, and flip vertex group names, copying when only one side is selected."; + ot->description= "Mirror weights, and flip vertex group names, copying when only one side is selected"; /* api callbacks */ ot->poll= vertex_group_poll_edit; @@ -1758,9 +1809,9 @@ 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."; + ot->description= "Copy Vertex Groups to all users of the same Geometry data"; /* api callbacks */ ot->poll= vertex_group_poll; @@ -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}}; @@ -1818,7 +1899,7 @@ void OBJECT_OT_vertex_group_set_active(wmOperatorType *ot) /* identifiers */ ot->name= "Set Active Vertex Group"; ot->idname= "OBJECT_OT_vertex_group_set_active"; - ot->description= "Set the active vertex group."; + ot->description= "Set the active vertex group"; /* api callbacks */ ot->poll= vertex_group_poll; @@ -1900,7 +1981,7 @@ void OBJECT_OT_vertex_group_sort(wmOperatorType *ot) { ot->name= "Sort Vertex Groups"; ot->idname= "OBJECT_OT_vertex_group_sort"; - ot->description= "Sorts vertex groups alphabetically."; + ot->description= "Sorts vertex groups alphabetically"; /* api callbacks */ ot->poll= vertex_group_poll; |