[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58003] trunk/blender/source/blender/ editors/object/object_vgroup.c: changes to weight paint transfer

Campbell Barton ideasman42 at gmail.com
Thu Jul 4 21:34:49 CEST 2013


Revision: 58003
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58003
Author:   campbellbarton
Date:     2013-07-04 19:34:49 +0000 (Thu, 04 Jul 2013)
Log Message:
-----------
changes to weight paint transfer
- Use the active group of the active (target) object (not the active group of the other, unselected object)
- Ensure the active group doesnt change from the one that was set originally.
- defgroup_find_name was doing redundant lookup on its self.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/object/object_vgroup.c

Modified: trunk/blender/source/blender/editors/object/object_vgroup.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_vgroup.c	2013-07-04 19:29:04 UTC (rev 58002)
+++ trunk/blender/source/blender/editors/object/object_vgroup.c	2013-07-04 19:34:49 UTC (rev 58003)
@@ -749,10 +749,12 @@
 	unsigned int f_index;
 	float weight, tmp_weight[4], tmp_co[3], normal[3], tmp_mat[4][4], dist_v1, dist_v2, dist_v3, dist_v4;
 	const int use_vert_sel = vertex_group_use_vert_sel(ob_dst);
+	bool is_dg_dst_new = false;
 
 	/* Ensure vertex group on target.*/
 	if ((dg_dst = defgroup_find_name(ob_dst, dg_src->name)) == NULL) {
 		dg_dst = BKE_defgroup_new(ob_dst, dg_src->name);
+		is_dg_dst_new = true;
 	}
 
 	/* Get meshes.*/
@@ -804,7 +806,10 @@
 			if (ob_dst == ob_src || dv_tot_dst == 0 || dv_tot_dst != dv_tot_src ||
 			    dv_array_src == NULL || dv_array_dst == NULL)
 			{
-				ED_vgroup_delete(ob_dst, defgroup_find_name(ob_dst, dg_dst->name));
+				if (is_dg_dst_new) {
+					ED_vgroup_delete(ob_dst, dg_dst);
+				}
+
 				if (dv_array_src) MEM_freeN(dv_array_src);
 				if (dv_array_dst) MEM_freeN(dv_array_dst);
 				dmesh_src->release(dmesh_src);
@@ -901,18 +906,16 @@
 				project_v3_plane(tmp_co, normal, mv_src[mf->v1].co);
 
 				/* Interpolate weights over face.*/
-				f_index = mf->v4 ? 3 : 2;
-				if (f_index == 3) {
-					interp_weights_face_v3(tmp_weight, mv_src[mf->v1].co, mv_src[mf->v2].co,
-					                       mv_src[mf->v3].co, mv_src[mf->v4].co, tmp_co);
-				}
-				else {
-					interp_weights_face_v3(tmp_weight, mv_src[mf->v1].co, mv_src[mf->v2].co,
-					                       mv_src[mf->v3].co, NULL, tmp_co);
-				}
+				interp_weights_face_v3(tmp_weight,
+				                       mv_src[mf->v1].co,
+				                       mv_src[mf->v2].co,
+				                       mv_src[mf->v3].co,
+				                       mf->v4 ? mv_src[mf->v4].co : NULL,
+				                       tmp_co);
 
 				/* Get weights from face.*/
-				weight = 0;
+				f_index = mf->v4 ? 3 : 2;
+				weight = 0.0f;
 				do {
 					v_index = (&mf->v1)[f_index];
 					weight += tmp_weight[f_index] * defvert_find_weight(dv_array_src[v_index], index_src);
@@ -920,7 +923,7 @@
 
 				/* Copy weight that are not NULL including weight value 0. In relevant cases, existing weights are
 				 * overwritten prior to this. See the "Clear weights." step above.*/
-				if (weight > 0) {
+				if (weight > 0.0f) {
 					dw_dst = defvert_verify_index(*dv_dst, index_dst);
 					vgroup_transfer_weight(&dw_dst->weight, weight, replace_mode);
 				}
@@ -3764,6 +3767,10 @@
 {
 	Scene *scene = CTX_data_scene(C);
 	Object *ob_act = CTX_data_active_object(C);
+
+	bDeformGroup *dg_act = BLI_findlink(&ob_act->defbase, (ob_act->actdef - 1));
+	char dg_act_name[MAX_VGROUP_NAME];  /* may be freed so copy */
+
 	int fail = 0;
 	bool change = false;
 
@@ -3771,6 +3778,17 @@
 	WT_Method method = RNA_enum_get(op->ptr, "method");
 	WT_ReplaceMode replace_mode = RNA_enum_get(op->ptr, "replace_mode");
 
+	if (vertex_group_mode == WT_REPLACE_ACTIVE_VERTEX_GROUP) {
+		if (!dg_act) {
+			BKE_report(op->reports, RPT_WARNING, "Failed, active object has no active groups");
+			return OPERATOR_CANCELLED;
+		}
+	}
+
+	if (dg_act) {
+		BLI_strncpy(dg_act_name, dg_act->name, sizeof(dg_act_name));
+	}
+
 	/* Macro to loop through selected objects and perform operation depending on function, option and method.*/
 	CTX_DATA_BEGIN (C, Object *, ob_src, selected_editable_objects)
 	{
@@ -3823,8 +3841,18 @@
 	CTX_DATA_END;
 
 	if (change) {
+
+		/* possible the active vertex group changed because of adding/removing */
+		/* note!, dg_act may be realloc'd, only check its not NULL */
+		if (dg_act) {
+			ED_vgroup_select_by_name(ob_act, dg_act_name);
+		}
+
 		/* Event notifiers for correct display of data.*/
+
+
 		DAG_id_tag_update(&ob_act->id, OB_RECALC_DATA);
+		WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob_act);  /* for buttons */
 		WM_event_add_notifier(C, NC_GEOM | ND_VERTEX_GROUP, ob_act);
 		return OPERATOR_FINISHED;
 	}




More information about the Bf-blender-cvs mailing list