[Bf-blender-cvs] [a5ac42bee46] PSketch-279: PSketch BBone WIP: Further attempts to get a better result

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


Commit: a5ac42bee466893afd0993cf1ebe03c75e9b3f9f
Author: Joshua Leung
Date:   Wed Jan 3 19:48:26 2018 +1300
Branches: PSketch-279
https://developer.blender.org/rBa5ac42bee466893afd0993cf1ebe03c75e9b3f9f

PSketch BBone WIP: Further attempts to get a better result

* Cope with reversed strokes better (instead of just converting them
  back to forward order)

* Experiment with different error thresholds to find something that
  works better. So far it's been getting worse...

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

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 bd04dedd25e..38e595ca2eb 100644
--- a/source/blender/editors/armature/pose_sketch.c
+++ b/source/blender/editors/armature/pose_sketch.c
@@ -556,38 +556,52 @@ static void psketch_pchan_apply_bbone_from_endpoints(
 	float mat[4][4], imat[4][4]; 
 	
 	mul_m4_m4m4(mat, ob->obmat, pchan->bone->arm_mat);
+	//mul_m4_m4m4(mat, ob->obmat, pchan->chan_mat);
 	invert_m4_m4(imat, mat);
 	
 	/* Convert input stroke data to a coordinates array (for fitting) */
-	bGPDspoint *start_pt = NULL;
 	int stroke_len = 0;
 	float *points = NULL;
 	
 	if (p1->index > p2->index) {
 		/* Reversed bone/stroke - p2 follows p1 */
-		start_pt = &stroke->points[p2->index];
+		bGPDspoint *pt = &stroke->points[p1->index];
+		
 		stroke_len = (p1->index - p2->index);
 		printf("R stroke_len = %d (%d -> %d)\n", stroke_len, p1->index, p2->index);
+		
+		points = MEM_mallocN(sizeof(*points) * stroke_len * 3, __func__);
+	
+		for (size_t i = 0; i < stroke_len; i++, pt--) {
+			float v[3];
+			
+			copy_v3_v3(v, &pt->x);
+			mul_mat3_m4_v3(imat, v);
+			
+			copy_v3_v3(points + (3 * i), v);
+		}
 	}
 	else {
 		/* p2 follows p1 in normal (forward) order */
-		start_pt = &stroke->points[p1->index];
+		bGPDspoint *pt = &stroke->points[p1->index];
+		
 		stroke_len = (p2->index - p1->index);
-		printf("stroke_len = %d (%d -> %d)\n", stroke_len, p1->index, p2->index);	
-	}
-	
-	points = MEM_mallocN(sizeof(*points) * stroke_len * 3, __func__);
-	
-	for (size_t i = 0; i < stroke_len; i++) {
-		bGPDspoint *pt = start_pt + i;
-		float v[3];
+		printf("stroke_len = %d (%d -> %d)\n", stroke_len, p1->index, p2->index);
 		
-		copy_v3_v3(v, &pt->x);
-		mul_mat3_m4_v3(imat, v);
+		points = MEM_mallocN(sizeof(*points) * stroke_len * 3, __func__);
 		
-		copy_v3_v3(points + (3 * i), v);
+		for (size_t i = 0; i < stroke_len; i++, pt++) {
+			float v[3];
+			
+			copy_v3_v3(v, &pt->x);
+			mul_mat3_m4_v3(imat, v);
+			
+			copy_v3_v3(points + (3 * i), v);
+		}
 	}
 	
+	
+	
 	/* 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
@@ -603,8 +617,8 @@ static void psketch_pchan_apply_bbone_from_endpoints(
 	/* Fit a single segment */
 	float in_handle[3], out_handle[3];
 	
-	const float error_threshold = 0.2f; // XXX: Draw Curve regularly uses 0.15
-	float err_squared = 0.0f;
+	const float error_threshold = 0.1f; // XXX: Draw Curve regularly uses 0.15
+	float r_err_squared = 0.0f;
 	unsigned int r_error_index = 0;
 	
 	int result = curve_fit_cubic_to_points_single_fl(
@@ -612,9 +626,9 @@ static void psketch_pchan_apply_bbone_from_endpoints(
 			3, error_threshold,
 			tan_l, tan_r,
 			in_handle, out_handle,
-			&err_squared, &r_error_index);
+			&r_err_squared, &r_error_index);
 	
-	printf("Curve Fit: result = %d, err = %f\n", result, err_squared);
+	printf("Curve Fit: result = %d, err = %f (%d)\n", result, r_err_squared, r_error_index);
 	if (result == 0) {
 		pchan->curveInX = in_handle[0];
 		pchan->curveInY = in_handle[2];



More information about the Bf-blender-cvs mailing list