[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45363] branches/meshdata_transfer/source/ blender/editors/object: Removed: The uneccecary previously added code and added functions for " copy_to_selected_single.

Ove Murberg Henriksen sorayasilvermoon at hotmail.com
Tue Apr 3 10:23:11 CEST 2012


Revision: 45363
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45363
Author:   cyborgmuppet
Date:     2012-04-03 08:23:00 +0000 (Tue, 03 Apr 2012)
Log Message:
-----------
Removed: The uneccecary previously added code and added functions for "copy_to_selected_single.
Reason: less code and  consistensy with existing code.

Added fuction "ED_vgroup_copy_single" that forms the basis for the above. 

Modified Paths:
--------------
    branches/meshdata_transfer/source/blender/editors/object/object_intern.h
    branches/meshdata_transfer/source/blender/editors/object/object_ops.c
    branches/meshdata_transfer/source/blender/editors/object/object_vgroup.c

Modified: branches/meshdata_transfer/source/blender/editors/object/object_intern.h
===================================================================
--- branches/meshdata_transfer/source/blender/editors/object/object_intern.h	2012-04-03 07:35:50 UTC (rev 45362)
+++ branches/meshdata_transfer/source/blender/editors/object/object_intern.h	2012-04-03 08:23:00 UTC (rev 45363)
@@ -201,8 +201,6 @@
 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);
-void OBJECT_OT_vertex_group_transfer_weight_all(struct wmOperatorType *ot);
-void OBJECT_OT_vertex_group_transfer_weight(struct wmOperatorType *ot);
 void OBJECT_OT_vertex_group_levels(struct wmOperatorType *ot);
 void OBJECT_OT_vertex_group_lock(struct wmOperatorType *ot);
 void OBJECT_OT_vertex_group_fix(struct wmOperatorType *ot);

Modified: branches/meshdata_transfer/source/blender/editors/object/object_ops.c
===================================================================
--- branches/meshdata_transfer/source/blender/editors/object/object_ops.c	2012-04-03 07:35:50 UTC (rev 45362)
+++ branches/meshdata_transfer/source/blender/editors/object/object_ops.c	2012-04-03 08:23:00 UTC (rev 45363)
@@ -174,8 +174,6 @@
 	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);
-	WM_operatortype_append(OBJECT_OT_vertex_group_transfer_weight_all);
-	WM_operatortype_append(OBJECT_OT_vertex_group_transfer_weight);
 	WM_operatortype_append(OBJECT_OT_vertex_group_lock);
 	WM_operatortype_append(OBJECT_OT_vertex_group_fix);
 	WM_operatortype_append(OBJECT_OT_vertex_group_invert);

Modified: branches/meshdata_transfer/source/blender/editors/object/object_vgroup.c
===================================================================
--- branches/meshdata_transfer/source/blender/editors/object/object_vgroup.c	2012-04-03 07:35:50 UTC (rev 45362)
+++ branches/meshdata_transfer/source/blender/editors/object/object_vgroup.c	2012-04-03 08:23:00 UTC (rev 45363)
@@ -312,7 +312,7 @@
 	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;
@@ -377,7 +377,44 @@
 	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 */
 static void ED_vgroup_nr_vert_add(Object *ob,
@@ -2653,7 +2690,7 @@
 	return OPERATOR_FINISHED;
 }
 
-/*Copy vertex groups from source to target*/ /*warning! overwrites list*/
+/* Transfer all vertex groups with weight to selected*/
 void OBJECT_OT_vertex_group_copy_to_selected(wmOperatorType *ot)
 {
 	/* identifiers */
@@ -2675,18 +2712,19 @@
 	int change= 0;
 	int fail= 0;
 
-	bDeformGroup *dg;
-	dg = BLI_findlink(&obact->defbase, (obact->actdef-1));
-
+	/*Macro to loop through selected objects and perform operation*/
 	CTX_DATA_BEGIN(C, Object*, obslc, selected_editable_objects)
 	{
 		if(obact != obslc) {
-			if(ED_vgroup_add_name(obslc, dg->name)) change++;
+			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",
@@ -2696,8 +2734,8 @@
 	return OPERATOR_FINISHED;
 }
 
-/*Copy a vertex group from source to targets*/
-void OBJECT_OT_vertex_group_copy_to_selected_single(wmOperatorType *ot) /*Todo: add gui in python*/
+/*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";
@@ -2706,85 +2744,12 @@
 
 	/* api callbacks */
 	ot->poll= vertex_group_poll;
-	ot->exec= vertex_group_copy_to_selected_exec;
+	ot->exec= vertex_group_copy_to_selected_single_exec;
 
 	/* flags */
 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-static void vgroup_copy_weight_all(const bContext *C, wmOperator *op)
-{
-	/* for each vertex group {defvert_copy(sourceGroup, targetGroup)} */
-	printf("Not implemented yet! \n");
-}
-
-static int vertex_group_transfer_weight_all_exec(const bContext *C, wmOperator *op)
-{
-	Object *ob = CTX_data_active_object(C);
-
-	vertex_group_copy_to_selected_exec(C, op); /*!!!This causes all vertex groups to be copied, weight or not.*/
-	vgroup_copy_weight_all(C, op);
-
-	/*is the right stuff being updated?*/
-	DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-	WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data);
-	WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
-
-	return OPERATOR_FINISHED;
-}
-
-/* Transfers all vertex groups with weight from source to targets*/
-void OBJECT_OT_vertex_group_transfer_weight_all(wmOperatorType *ot)
-{
-	/* identifiers */
-	ot->name= "Transfer Weight All";
-	ot->idname= "OBJECT_OT_vertex_group_transfer_weight_all";
-	ot->description= "Copy all vertex groups including weights to targets";
-
-	/* api callbacks */
-	ot->poll= vertex_group_poll;
-	ot->exec= vertex_group_transfer_weight_all_exec;
-
-	/* flags */
-	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-
-static void vgroup_copy_weight(const bContext *C, wmOperator *op)
-{
-	printf("Not implemented yet! \n");
-}
-
-static int vertex_group_transfer_weight_exec(const bContext *C, wmOperator *op)
-{
-	Object *ob = CTX_data_active_object(C);
-
-	vertex_group_copy_to_selected_single_exec(C,op); /*!!!This will copy vertex grop, weight or not.*/
-	vgroup_copy_weight(C, op);
-
-	/*is the right stuff being updated?*/
-	DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-	WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data);
-	WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
-
-	return OPERATOR_FINISHED;
-}
-
-/* Transfers one vertex group with weight from source to targets*/
-void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot)
-{
-	/* identifiers */
-	ot->name= "Transfer Weight";
-	ot->idname= "OBJECT_OT_vertex_group_transfer_weight";
-	ot->description= "Copy a vertex group including weights to targets";
-
-	/* api callbacks */
-	ot->poll= vertex_group_poll;
-	ot->exec= vertex_group_transfer_weight_exec;
-
-	/* flags */
-	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-
 static EnumPropertyItem vgroup_items[]= {
 	{0, NULL, 0, NULL, NULL}};
 




More information about the Bf-blender-cvs mailing list