[Bf-blender-cvs] [fc105bd738a] PSketch-279: Cleanup: Refactor out BBone "closest-bone-end-factor" logic

Joshua Leung noreply at git.blender.org
Tue May 8 18:03:43 CEST 2018


Commit: fc105bd738a165701df7cb466a7fe7011a342daf
Author: Joshua Leung
Date:   Tue Jan 2 16:16:43 2018 +1300
Branches: PSketch-279
https://developer.blender.org/rBfc105bd738a165701df7cb466a7fe7011a342daf

Cleanup: Refactor out BBone "closest-bone-end-factor" logic

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

M	source/blender/editors/armature/pose_sculpt.c

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

diff --git a/source/blender/editors/armature/pose_sculpt.c b/source/blender/editors/armature/pose_sculpt.c
index 9973ccf185b..310bab5d12d 100644
--- a/source/blender/editors/armature/pose_sculpt.c
+++ b/source/blender/editors/armature/pose_sculpt.c
@@ -306,6 +306,7 @@ static void psculpt_brush_header_info(bContext *C)
 /* ******************************************************** */
 /* Brush Utilities */
 
+/* calculate brush influence given the distance of the cursor from a bone */
 static float psculpt_brush_calc_influence(tPoseSculptingOp *pso, float dist)
 {
 	PSculptBrushData *brush = pso->brush;
@@ -326,6 +327,50 @@ static float psculpt_brush_calc_influence(tPoseSculptingOp *pso, float dist)
 	return fac;
 }
 
+/* determine which end of a bendy bone is affected, and the effect strength */
+static float psculpt_brush_calc_bendybone_influence(
+        tPoseSculptingOp *pso, 
+        float dist, 
+        float sco1[2], float sco2[2], 
+        bool *do_head, bool *do_tail)
+{
+	float d1, d2, dm;
+	float mid[2];
+	float fac;
+	
+	/* init do_head/tail values first (in case neither gets set) */
+	*do_head = false;
+	*do_tail = false;
+	
+	/* compute screenspace distances from cursor to bone endpoints */
+	d1 = len_v2v2(pso->mval, sco1);
+	d2 = len_v2v2(pso->mval, sco2);
+	
+	mid_v2_v2v2(mid, sco1, sco2);
+	dm = len_v2v2(pso->mval, mid);
+	
+	/* which point is closer to the cursor? */
+	if (d1 < d2) {
+		/* Head (In) */
+		fac = psculpt_brush_calc_influence(pso, d1);
+		*do_head = true;
+	}
+	else if (d2 < d1) {
+		/* Tail (Out) */
+		fac = psculpt_brush_calc_influence(pso, d2);
+		*do_tail = true;
+	}
+	else {
+		/* Affect both by the same amount */
+		fac = psculpt_brush_calc_influence(pso, dist);	
+		*do_head = true;
+		*do_tail = true;
+	}
+	
+	/* return the best-guess of the most appropriate influence to use */
+	return fac;
+}
+
 /* ........................................................ */
 
 /* compute volume preservation scale factor (for xz axes) */
@@ -1520,9 +1565,6 @@ static void psculpt_brush_push_apply(tPoseSculptingOp *pso, bPoseChannel *pchan,
 	float imat[4][4], mat[4][4];
 	float delta[3], vec[3];
 	
-	float d1, d2, dm;
-	float mid[2];
-	
 	bool do_head = false, do_tail = false;
 	bool do_x = false, do_z = false;
 	bool do_ease = pso->invert;
@@ -1558,28 +1600,7 @@ static void psculpt_brush_push_apply(tPoseSculptingOp *pso, bPoseChannel *pchan,
 	mul_mat3_m4_v3(imat, delta);
 	
 	/* figure out which end is affected more */
-	d1 = len_v2v2(pso->mval, sco1);
-	d2 = len_v2v2(pso->mval, sco2);
-	
-	mid_v2_v2v2(mid, sco1, sco2);
-	dm = len_v2v2(pso->mval, mid);
-	
-	if (d1 < d2) {
-		/* Head (In) */
-		fac = psculpt_brush_calc_influence(pso, d1);
-		do_head = true;
-	}
-	else if (d2 < d1) {
-		/* Tail (Out) */
-		fac = psculpt_brush_calc_influence(pso, d2);
-		do_tail = true;
-	}
-	else {
-		/* Affect both by the same amount */
-		fac = psculpt_brush_calc_influence(pso, dist);	
-		do_head = do_tail = true;
-	}
-	
+	fac = psculpt_brush_calc_bendybone_influence(pso, dist, sco1, sco2, &do_head, &do_tail);
 	
 	/* affect x/z axes? */
 	if (ELEM(brush->xzMode, PSCULPT_BRUSH_DO_XZ, PSCULPT_BRUSH_DO_X)) {



More information about the Bf-blender-cvs mailing list