[Bf-blender-cvs] [28c4d6ef05c] hair_guides_grooming: Make the hair binding function more robust when no guide curves are defined.

Lukas Tönne noreply at git.blender.org
Sat Jun 9 10:59:01 CEST 2018


Commit: 28c4d6ef05ccea6626baebcd52c6bdf89f8aef6c
Author: Lukas Tönne
Date:   Sat Jun 9 09:49:33 2018 +0100
Branches: hair_guides_grooming
https://developer.blender.org/rB28c4d6ef05ccea6626baebcd52c6bdf89f8aef6c

Make the hair binding function more robust when no guide curves are defined.

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

M	source/blender/blenkernel/BKE_hair.h
M	source/blender/blenkernel/intern/hair.c

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

diff --git a/source/blender/blenkernel/BKE_hair.h b/source/blender/blenkernel/BKE_hair.h
index be27b02c8c8..cad25348e43 100644
--- a/source/blender/blenkernel/BKE_hair.h
+++ b/source/blender/blenkernel/BKE_hair.h
@@ -117,7 +117,7 @@ void BKE_hair_generate_follicles_ex(
         int count,
         const float *loop_weights);
 
-void BKE_hair_bind_follicles(struct HairSystem *hsys, const struct Mesh *scalp);
+bool BKE_hair_bind_follicles(struct HairSystem *hsys, const struct Mesh *scalp);
 
 /* === Draw Settings === */
 
diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c
index bf78222a42b..cca003142da 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -411,49 +411,72 @@ static void hair_fiber_find_closest_strand(
 	hair_fiber_sort_weights(follicle);
 }
 
-void BKE_hair_bind_follicles(HairSystem *hsys, const Mesh *scalp)
+bool BKE_hair_bind_follicles(HairSystem *hsys, const Mesh *scalp)
 {
 	if (!(hsys->flag & HAIR_SYSTEM_UPDATE_FOLLICLE_BINDING))
 	{
-		return;
+		return true;
 	}
 	hsys->flag &= ~HAIR_SYSTEM_UPDATE_FOLLICLE_BINDING;
 	
 	HairPattern *pattern = hsys->pattern;
 	if (!pattern)
-		return;
+	{
+		return true;
+	}
 	
 	const int num_strands = hsys->guides.totcurves;
 	/* Need at least one guide curve for binding */
-	BLI_assert(num_strands > 0);
+	if (num_strands == 0)
+	{
+		HairFollicle *follicle = pattern->follicles;
+		for (int i = 0; i < pattern->num_follicles; ++i, ++follicle)
+		{
+			for (int k = 0; k < 4; ++k)
+			{
+				follicle->parent_index[k] = HAIR_STRAND_INDEX_NONE;
+				follicle->parent_weight[k] = 0.0f;
+			}
+		}
+		return false;
+	}
 	
 	float (*strandloc)[3] = MEM_mallocN(sizeof(float) * 3 * num_strands, "strand locations");
 	{
-		for (int i = 0; i < num_strands; ++i) {
+		for (int i = 0; i < num_strands; ++i)
+		{
 			float nor[3], tang[3];
-			if (!BKE_mesh_sample_eval(scalp, &hsys->guides.curves[i].mesh_sample, strandloc[i], nor, tang)) {
+			if (!BKE_mesh_sample_eval(scalp, &hsys->guides.curves[i].mesh_sample, strandloc[i], nor, tang))
+			{
 				zero_v3(strandloc[i]);
 			}
 		}
 	}
 	
 	KDTree *tree = BLI_kdtree_new(num_strands);
-	for (int c = 0; c < num_strands; ++c) {
+	for (int c = 0; c < num_strands; ++c)
+	{
 		BLI_kdtree_insert(tree, c, strandloc[c]);
 	}
 	BLI_kdtree_balance(tree);
 	
-	HairFollicle *follicle = pattern->follicles;
-	for (int i = 0; i < pattern->num_follicles; ++i, ++follicle) {
-		float loc[3], nor[3], tang[3];
-		if (BKE_mesh_sample_eval(scalp, &follicle->mesh_sample, loc, nor, tang)) {
-			hair_fiber_find_closest_strand(follicle, loc, tree, strandloc);
-			hair_fiber_verify_weights(follicle);
+	{
+		HairFollicle *follicle = pattern->follicles;
+		for (int i = 0; i < pattern->num_follicles; ++i, ++follicle)
+		{
+			float loc[3], nor[3], tang[3];
+			if (BKE_mesh_sample_eval(scalp, &follicle->mesh_sample, loc, nor, tang))
+			{
+				hair_fiber_find_closest_strand(follicle, loc, tree, strandloc);
+				hair_fiber_verify_weights(follicle);
+			}
 		}
 	}
 	
 	BLI_kdtree_free(tree);
 	MEM_freeN(strandloc);
+	
+	return true;
 }
 
 /* === Export === */



More information about the Bf-blender-cvs mailing list