svn merge ^/trunk/blender -r44562:45364
authorOve Murberg Henriksen <sorayasilvermoon@hotmail.com>
Tue, 3 Apr 2012 11:55:39 +0000 (11:55 +0000)
committerOve Murberg Henriksen <sorayasilvermoon@hotmail.com>
Tue, 3 Apr 2012 11:55:39 +0000 (11:55 +0000)
source/blender/editors/object/object_intern.h
source/blender/editors/object/object_ops.c
source/blender/editors/object/object_vgroup.c

index 73c5c50f448d5629174039808ea71de3a36bb49a..19eb3575241c1f00b3d9cb32ae08bb7ab9f0ac2e 100644 (file)
@@ -196,6 +196,7 @@ 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_to_selected_single(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);
index 12387f36ca413c3ca693e84194e27f83dc9bafc3..115d452fd4eaf90b05a0d01617a049892e16c010 100644 (file)
@@ -170,6 +170,7 @@ void ED_operatortypes_object(void)
        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_to_selected_single);
        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);
index a87268a24024a4fc08ba88ffeac6d40aa1765c1d..c0150d6e3b06c28a443543341362a929d81bb101 100644 (file)
@@ -20,7 +20,7 @@
  *
  * The Original Code is: all of this file.
  *
- * Contributor(s): none yet.
+ * Contributor(s): Ove M Henriksen
  *
  * ***** END GPL LICENSE BLOCK *****
  */
@@ -75,6 +75,7 @@
 #include "UI_resources.h"
 
 #include "object_intern.h"
+#include <stdio.h> /*only for development purposes, remove*/
 
 /************************ Exported Functions **********************/
 static void vgroup_remap_update_users(Object *ob, int *map);
@@ -311,7 +312,7 @@ int ED_vgroup_give_array(ID *id, MDeformVert **dvert_arr, int *dvert_tot)
        return FALSE;
 }
 
-/* matching index only */
+/*Copy all vertex groups to target, overwriting existing. matching index only*/
 int ED_vgroup_copy_array(Object *ob, Object *ob_from)
 {
        MDeformVert **dvert_array_from, **dvf;
@@ -376,6 +377,43 @@ int ED_vgroup_copy_array(Object *ob, Object *ob_from)
        return 1;
 }
 
+/*Copy a single vertex group from source to destination with weights*/
+int ED_vgroup_copy_single(Object *ob_dst, const Object *ob_src)
+{
+       MDeformVert **dv_array_src;
+       MDeformVert **dv_array_dst;
+       MDeformWeight *dw_dst, *dw_src;
+       int dv_tot_src, dv_tot_dst;
+       int i, index_src, index_dst;
+       bDeformGroup *dg_src, *dg_dst;
+
+       /*get source deform group*/
+       dg_src = BLI_findlink(&ob_src->defbase, (ob_src->actdef-1));
+
+       /*Create new and overwrite vertex group on destination without data*/
+       ED_vgroup_delete(ob_dst, defgroup_find_name(ob_dst, dg_src->name));
+       ED_vgroup_add_name(ob_dst, dg_src->name);
+
+       /*get destination deformgroup*/
+       dg_dst= defgroup_find_name(ob_dst, dg_src->name);
+
+       /*get vertex group arrays*/
+       ED_vgroup_give_parray(ob_src->data, &dv_array_src, &dv_tot_src, FALSE);
+       ED_vgroup_give_parray(ob_dst->data, &dv_array_dst, &dv_tot_dst, FALSE);
+
+       /*get indexes of vertex groups*/
+       index_src= BLI_findindex(&ob_src->defbase, dg_src);
+       index_dst= BLI_findindex(&ob_dst->defbase, dg_dst);
+
+       /* Loop through the vertices and copy weight*/
+       for(i=0; i<dv_tot_dst; i++, dv_array_src++, dv_array_dst++) {
+               dw_src = defvert_verify_index(*dv_array_src, index_src);
+               dw_dst = defvert_verify_index(*dv_array_dst, index_dst);
+               dw_dst->weight = dw_src->weight;
+       }
+
+       return 1;
+}
 
 /* for Mesh in Object mode */
 /* allows editmode for Lattice */
@@ -1177,7 +1215,6 @@ static void vgroup_normalize_all(Object *ob, int lock_active)
        }
 }
 
-
 static void vgroup_lock_all(Object *ob, int action)
 {
        bDeformGroup *dg;
@@ -2293,6 +2330,7 @@ void OBJECT_OT_vertex_group_deselect(wmOperatorType *ot)
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+/*Adds a copy of selected vertex group from source object to source object*/
 static int vertex_group_copy_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *ob= ED_object_context(C);
@@ -2705,6 +2743,7 @@ void OBJECT_OT_vertex_group_copy_to_linked(wmOperatorType *ot)
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+/*Copy vertex groups from source to target*/ /*warning! overwrites list*/
 static int vertex_group_copy_to_selected_exec(bContext *C, wmOperator *op)
 {
        Object *obact= ED_object_context(C);
@@ -2729,7 +2768,7 @@ static int vertex_group_copy_to_selected_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-
+/* Transfer all vertex groups with weight to selected*/
 void OBJECT_OT_vertex_group_copy_to_selected(wmOperatorType *ot)
 {
        /* identifiers */
@@ -2745,6 +2784,50 @@ void OBJECT_OT_vertex_group_copy_to_selected(wmOperatorType *ot)
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+static int vertex_group_copy_to_selected_single_exec(bContext *C, wmOperator *op)
+{
+       Object *obact= CTX_data_active_object(C);
+       int change= 0;
+       int fail= 0;
+
+       /*Macro to loop through selected objects and perform operation*/
+       CTX_DATA_BEGIN(C, Object*, obslc, selected_editable_objects)
+       {
+               if(obact != obslc) {
+                       if(ED_vgroup_copy_single(obslc, obact)) change++;
+                       else                                fail++;
+                       /*event notifiers for correct display of data*/
+                       DAG_id_tag_update(&obslc->id, OB_RECALC_DATA);
+                       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obslc);
+                       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obslc->data);
+               }
+       }
+       CTX_DATA_END;
+       if((change == 0 && fail == 0) || fail) {
+               BKE_reportf(op->reports, RPT_ERROR,
+                           "Copy to VGroups to Selected warning done %d, failed %d, object data must have matching indicies",
+                           change, fail);
+       }
+
+       return OPERATOR_FINISHED;
+}
+
+/*Transfer vertex group with weight to selected*/
+void OBJECT_OT_vertex_group_copy_to_selected_single(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Copy a Vertex Group to Selected";
+       ot->idname= "OBJECT_OT_vertex_group_copy_to_selected_single";
+       ot->description= "Copy a vertex group to other selected objects with matching indices";
+
+       /* api callbacks */
+       ot->poll= vertex_group_poll;
+       ot->exec= vertex_group_copy_to_selected_single_exec;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
 static EnumPropertyItem vgroup_items[]= {
        {0, NULL, 0, NULL, NULL}};