[Bf-blender-cvs] [d7e6a6f] master: Fix T47152: Normalize fails w/ mirror group

Campbell Barton noreply at git.blender.org
Mon Jan 11 07:47:54 CET 2016


Commit: d7e6a6f4de5a03e9b581f1e92415848b6196bcfd
Author: Campbell Barton
Date:   Mon Jan 11 17:36:55 2016 +1100
Branches: master
https://developer.blender.org/rBd7e6a6f4de5a03e9b581f1e92415848b6196bcfd

Fix T47152: Normalize fails w/ mirror group

When the mirrored vertex group was created on the first stroke,
the mirrored weight failed to normalize.

aused by the valid vgroup map being created before adding the mirror vertex group.

===================================================================

M	source/blender/editors/sculpt_paint/paint_vertex.c

===================================================================

diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c
index 34870a1..4e8c2ad 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@ -2020,6 +2020,15 @@ void PAINT_OT_weight_paint_toggle(wmOperatorType *ot)
 
 /* ************ weight paint operator ********** */
 
+enum eWPaintFlag {
+	WPAINT_ENSURE_MIRROR = (1 << 0),
+};
+
+struct WPaintVGroupIndex {
+	int active;
+	int mirror;
+};
+
 struct WPaintData {
 	ViewContext vc;
 	int *indexar;
@@ -2038,12 +2047,19 @@ struct WPaintData {
 };
 
 /* ensure we have data on wpaint start, add if needed */
-static bool wpaint_ensure_data(bContext *C, wmOperator *op)
+static bool wpaint_ensure_data(
+        bContext *C, wmOperator *op,
+        enum eWPaintFlag flag, struct WPaintVGroupIndex *vgroup_index)
 {
 	Scene *scene = CTX_data_scene(C);
 	Object *ob = CTX_data_active_object(C);
 	Mesh *me = BKE_mesh_from_object(ob);
 
+	if (vgroup_index) {
+		vgroup_index->active = -1;
+		vgroup_index->mirror = -1;
+	}
+
 	if (scene->obedit) {
 		return false;
 	}
@@ -2090,6 +2106,14 @@ static bool wpaint_ensure_data(bContext *C, wmOperator *op)
 		return false;
 	}
 
+	vgroup_index->active = ob->actdef - 1;
+
+	if (flag & WPAINT_ENSURE_MIRROR) {
+		if (me->editflag & ME_EDIT_MIRROR_X) {
+			vgroup_index->mirror = wpaint_mirror_vgroup_ensure(ob, vgroup_index->active);
+		}
+	}
+
 	return true;
 }
 
@@ -2102,21 +2126,28 @@ static bool wpaint_stroke_test_start(bContext *C, wmOperator *op, const float UN
 	Object *ob = CTX_data_active_object(C);
 	Mesh *me = BKE_mesh_from_object(ob);
 	struct WPaintData *wpd;
+	struct WPaintVGroupIndex vgroup_index;
 
 	float mat[4][4], imat[4][4];
 
-	if (wpaint_ensure_data(C, op) == false) {
+	if (wpaint_ensure_data(C, op, WPAINT_ENSURE_MIRROR, &vgroup_index) == false) {
 		return false;
 	}
 
 	{
 		/* check if we are attempting to paint onto a locked vertex group,
 		 * and other options disallow it from doing anything useful */
-		bDeformGroup *dg = BLI_findlink(&ob->defbase, (ob->actdef - 1));
+		bDeformGroup *dg;
+		dg = BLI_findlink(&ob->defbase, vgroup_index.active);
 		if (dg->flag & DG_LOCK_WEIGHT) {
 			BKE_report(op->reports, RPT_WARNING, "Active group is locked, aborting");
 			return false;
 		}
+		dg = BLI_findlink(&ob->defbase, vgroup_index.mirror);
+		if (dg->flag & DG_LOCK_WEIGHT) {
+			BKE_report(op->reports, RPT_WARNING, "Mirror group is locked, aborting");
+			return false;
+		}
 	}
 
 	/* ALLOCATIONS! no return after this line */
@@ -2125,8 +2156,8 @@ static bool wpaint_stroke_test_start(bContext *C, wmOperator *op, const float UN
 	paint_stroke_set_mode_data(stroke, wpd);
 	view3d_set_viewcontext(C, &wpd->vc);
 
-	wpd->vgroup_active = ob->actdef - 1;
-	wpd->vgroup_mirror = -1;
+	wpd->vgroup_active = vgroup_index.active;
+	wpd->vgroup_mirror = vgroup_index.mirror;
 
 	/* set up auto-normalize, and generate map for detecting which
 	 * vgroups affect deform bones */
@@ -2147,11 +2178,6 @@ static bool wpaint_stroke_test_start(bContext *C, wmOperator *op, const float UN
 	invert_m4_m4(imat, mat);
 	copy_m3_m4(wpd->wpimat, imat);
 
-	/* if mirror painting, find the other group */
-	if (me->editflag & ME_EDIT_MIRROR_X) {
-		wpd->vgroup_mirror = wpaint_mirror_vgroup_ensure(ob, wpd->vgroup_active);
-	}
-	
 	return true;
 }
 
@@ -2510,7 +2536,7 @@ static int weight_paint_set_exec(bContext *C, wmOperator *op)
 	Brush *brush = BKE_paint_brush(&ts->wpaint->paint);
 	float vgroup_weight = BKE_brush_weight_get(scene, brush);
 
-	if (wpaint_ensure_data(C, op) == false) {
+	if (wpaint_ensure_data(C, op, WPAINT_ENSURE_MIRROR, NULL) == false) {
 		return OPERATOR_CANCELLED;
 	}
 
@@ -3206,7 +3232,7 @@ static int paint_weight_gradient_exec(bContext *C, wmOperator *op)
 		vert_cache = gesture->userdata;
 	}
 	else {
-		if (wpaint_ensure_data(C, op) == false) {
+		if (wpaint_ensure_data(C, op, 0, NULL) == false) {
 			return OPERATOR_CANCELLED;
 		}
 
@@ -3265,7 +3291,7 @@ static int paint_weight_gradient_invoke(bContext *C, wmOperator *op, const wmEve
 {
 	int ret;
 
-	if (wpaint_ensure_data(C, op) == false) {
+	if (wpaint_ensure_data(C, op, 0, NULL) == false) {
 		return OPERATOR_CANCELLED;
 	}




More information about the Bf-blender-cvs mailing list