[Bf-blender-cvs] [74ca67b] hair_system: Modification to bending spring calculation to handle the initial direction of the hair curve.

Lukas Tönne noreply at git.blender.org
Mon Oct 6 09:22:35 CEST 2014


Commit: 74ca67b56089e0e294d326aa1cb0abd6d150250c
Author: Lukas Tönne
Date:   Mon Oct 6 09:16:32 2014 +0200
Branches: hair_system
https://developer.blender.org/rB74ca67b56089e0e294d326aa1cb0abd6d150250c

Modification to bending spring calculation to handle the initial
direction of the hair curve.

Note that bending springs are a bit unstable for low bending stiffness
when there is not enough damping. This may be due to missing additional
derivatives on the previous segment (dependency of the frame), but
calculating these entirely could give a dense matrix instead ...

A more practical approach might be to make damping factors relative to
the stiffness and set a soft UI minimum of 10% or so. Values much below
that are not physically plausible anyway, given that any material has
internal friction on bending.

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

M	source/blender/blenkernel/intern/hair.c
M	source/blender/physics/intern/BPH_mass_spring.cpp

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

diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c
index e44b0c5..e7542bb 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -281,7 +281,7 @@ void BKE_hair_calculate_rest(struct DerivedMesh *dm, HairCurve *curve)
 	int k;
 	float tot_rest_length;
 	HairFrameIterator iter;
-	float frame[3][3], rot[3][3];
+	float frame[3][3], dir[3], rot[3][3];
 	
 	if (curve->totpoints < 2) {
 		point = curve->points;
@@ -310,14 +310,20 @@ void BKE_hair_calculate_rest(struct DerivedMesh *dm, HairCurve *curve)
 	BKE_hair_get_mesh_frame(dm, curve, curve->root_rest_frame);
 	copy_m3_m3(frame, curve->root_rest_frame);
 	
-	/* initialize frame iterator */
-	BKE_hair_frame_init(&iter, frame[2]);
-	
 	point = curve->points;
+	
 	/* target is the edge vector in frame space */
 	sub_v3_v3v3(point->rest_target, (point+1)->rest_co, point->rest_co);
 	mul_transposed_m3_v3(frame, point->rest_target);
 	
+	/* align frame to first segment */
+	sub_v3_v3v3(dir, (point+1)->rest_co, point->rest_co);
+	normalize_v3(dir);
+	rotation_between_vecs_to_mat3(rot, frame[2], dir);
+	mul_m3_m3m3(frame, rot, frame);
+	/* initialize frame iterator */
+	BKE_hair_frame_init(&iter, dir);
+	
 	++point;
 	for (k = 1; k < curve->totpoints - 1; ++k, ++point) {
 		/* transport the frame to the next segment */
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 8016d21..730be33 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -872,7 +872,7 @@ static void hair_calc_spring_force(HairSolverData *data, Object *ob, HairSystem
 #ifdef CLOTH_FORCE_SPRING_BEND
 		if (curve->totpoints >= 2) {
 			HairFrameIterator iter;
-			float x[3], x_prev[3], frame[3][3], rot[3][3], target[3];
+			float x[3], x_prev[3], dir[3], frame[3][3], rot[3][3], target[3];
 			
 			/* frame starts in current root position */
 			copy_m3_m3(frame, curve->root_frame);
@@ -881,9 +881,6 @@ static void hair_calc_spring_force(HairSolverData *data, Object *ob, HairSystem
 			mul_mat3_m4_v3(obmat, frame[2]);
 			normalize_m3(frame); /* avoid scaling from obmat */
 			
-			/* initialize frame iterator */
-			BKE_hair_frame_init(&iter, frame[2]);
-			
 			/* special handling of root point bending:
 			 * use the first point twice
 			 */
@@ -894,6 +891,20 @@ static void hair_calc_spring_force(HairSolverData *data, Object *ob, HairSystem
 			
 			/* initialize x as the first point */
 			BPH_mass_spring_get_motion_state(data->id, kstart, x, NULL);
+			BPH_mass_spring_get_motion_state(data->id, kstart + 1, dir, NULL);
+			sub_v3_v3(dir, x);
+			normalize_v3(dir);
+			
+			/* align frame to first segment */
+			rotation_between_vecs_to_mat3(rot, frame[2], dir);
+			mul_m3_m3m3(frame, rot, frame);
+			/* initialize frame iterator */
+			BKE_hair_frame_init(&iter, dir);
+			
+			{ /* XXX DEBUG */
+				BKE_sim_debug_data_add_m3(debug_data, x, frame, 0.8f*curve->avg_rest_length, 0.3f, 1.0f, "bending", hash_vertex(935, kstart));
+				BKE_sim_debug_data_add_vector(debug_data, x, target, 0.7, 0.8, 0.0, "bending", hash_vertex(945, kstart));
+			}
 			
 			++point;
 			for (int k = 1; k < curve->totpoints - 1; ++k, ++point) {
@@ -910,7 +921,7 @@ static void hair_calc_spring_force(HairSolverData *data, Object *ob, HairSystem
 				                                             params->bend_stiffness, params->bend_damping);
 				
 				{ /* XXX DEBUG */
-					BKE_sim_debug_data_add_m3(debug_data, x, frame, 0.2f, 0.3f, 1.0f, "bending", hash_vertex(935, kstart + k));
+					BKE_sim_debug_data_add_m3(debug_data, x, frame, 0.8f*curve->avg_rest_length, 0.3f, 1.0f, "bending", hash_vertex(935, kstart + k));
 					BKE_sim_debug_data_add_vector(debug_data, x, target, 0.7, 0.8, 0.0, "bending", hash_vertex(945, kstart + k));
 				}
 			}




More information about the Bf-blender-cvs mailing list