Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2010-02-10 01:00:19 +0300
committerCampbell Barton <ideasman42@gmail.com>2010-02-10 01:00:19 +0300
commitf22104542bf0025264934ba235b517abbe562c38 (patch)
tree2e5a482b15aefdd01ff1c9e6fdec6d0d76385931
parent59a508d00b60cee1573d0158c52a83e1b4e6f74b (diff)
copy vgroups to selected objects as long as they have aligned arrays.
access in the vertex group panel menu.
-rw-r--r--release/scripts/ui/properties_data_mesh.py1
-rw-r--r--source/blender/editors/include/ED_mesh.h1
-rw-r--r--source/blender/editors/object/object_intern.h1
-rw-r--r--source/blender/editors/object/object_ops.c1
-rw-r--r--source/blender/editors/object/object_vgroup.c83
5 files changed, 86 insertions, 1 deletions
diff --git a/release/scripts/ui/properties_data_mesh.py b/release/scripts/ui/properties_data_mesh.py
index 63daf3fc701..630dd5d1101 100644
--- a/release/scripts/ui/properties_data_mesh.py
+++ b/release/scripts/ui/properties_data_mesh.py
@@ -32,6 +32,7 @@ class MESH_MT_vertex_group_specials(bpy.types.Menu):
layout.operator("object.vertex_group_sort", icon='SORTALPHA')
layout.operator("object.vertex_group_copy", icon='COPY_ID')
layout.operator("object.vertex_group_copy_to_linked", icon='LINK_AREA')
+ layout.operator("object.vertex_group_copy_to_selected", icon='LINK_AREA')
layout.operator("object.vertex_group_mirror", icon='ARROW_LEFTRIGHT')
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; 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)
@@ -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}};