[Bf-blender-cvs] [c4a79a2cd35] PSketch-279: PSketch BBone Fit WIP (Attempt 2): Choose better initial handles instead

Joshua Leung noreply at git.blender.org
Tue May 8 18:04:05 CEST 2018


Commit: c4a79a2cd35fb3b19f72178ec87c58fb9d0a124d
Author: Joshua Leung
Date:   Wed Jan 3 20:44:49 2018 +1300
Branches: PSketch-279
https://developer.blender.org/rBc4a79a2cd35fb3b19f72178ec87c58fb9d0a124d

PSketch BBone Fit WIP (Attempt 2): Choose better initial handles instead

Now, we take the start, middle, and end points of the stroke, and calculate
the slopes between these points. For some reason, the fit seems better
when we invert the vector-subtraction order (as we've done now).

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

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

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

diff --git a/source/blender/editors/armature/pose_sketch.c b/source/blender/editors/armature/pose_sketch.c
index f46ea129fb8..e5d29f81bbe 100644
--- a/source/blender/editors/armature/pose_sketch.c
+++ b/source/blender/editors/armature/pose_sketch.c
@@ -611,18 +611,36 @@ static void psketch_pchan_apply_bbone_from_endpoints(
 	float r_err_squared = 0.0f;
 	unsigned int r_error_index = 0;
 	
-	do {
+	//do {
 		/* Generate an estimate for the unit "proto" handles the handles
 		 * should be aligned to. As an initial guess, let's use the BBone
 		 * handles, and then invert the "right" (tail) one to face the same
 		 * direction as the bone.
 		 */
+#if 0
 		// TODO: Do we need to include the rest values too?
 		float tan_l[3] = {pchan->curveInX, 0, pchan->curveInY};
 		float tan_r[3] = {pchan->curveOutX, 0, pchan->curveOutY};
 		
 		normalize_v3(tan_l);
 		normalize_v3(tan_r);
+#else
+		/* As an initial guess, let's use the slopes for the two halves of
+		 * the stroke as an estimate of what we need.
+		 */
+		const size_t mid_idx  = (stroke_len / 2);
+		const size_t last_idx = (stroke_len - 1); 
+		
+		float v1[3], v2[3], v3[3];
+		float tan_l[3], tan_r[3];
+		
+		copy_v3_v3(v1, points);
+		copy_v3_v3(v2, points + (3 * mid_idx));
+		copy_v3_v3(v3, points + (3 * last_idx));
+		
+		sub_v3_v3v3(tan_l, v1, v2);
+		sub_v3_v3v3(tan_r, v2, v3);
+#endif
 		
 		/* Fit a single segment */
 		float in_handle[3], out_handle[3];
@@ -645,7 +663,7 @@ static void psketch_pchan_apply_bbone_from_endpoints(
 			//pchan->ease1 = in_handle[1];		
 			//pchan->ease2 = out_handle[1];
 		}
-	} while ((r_err_squared > 1.0f) && (cur_iter++ < max_iters));
+	//} while ((r_err_squared > 1.0f) && (cur_iter++ < max_iters));
 	
 	/* free data */
 	MEM_freeN(points);



More information about the Bf-blender-cvs mailing list