[Bf-blender-cvs] [2d8c39c97cb] hair_guides 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:58:59 CEST 2018
Commit: 2d8c39c97cb211e14bba1e7ced3a4c41cc1c7f9d
Author: Lukas Tönne
Date: Sat Jun 9 09:49:33 2018 +0100
Branches: hair_guides hair_guides_grooming
https://developer.blender.org/rB2d8c39c97cb211e14bba1e7ced3a4c41cc1c7f9d
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 1f74caa79e0..ec9f0601485 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, struct Mesh *scalp);
+bool BKE_hair_bind_follicles(struct HairSystem *hsys, struct Mesh *scalp);
/* === Draw Settings === */
diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c
index 92567e5efe9..c007ae3a325 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -413,46 +413,72 @@ static void hair_fiber_find_closest_strand(
hair_fiber_sort_weights(follicle);
}
-void BKE_hair_bind_follicles(HairSystem *hsys, Mesh *scalp)
+bool BKE_hair_bind_follicles(HairSystem *hsys, 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 true;
+ }
+
const int num_strands = hsys->guides.totcurves;
- if (num_strands == 0 || !pattern)
- return;
+ /* Need at least one guide curve for binding */
+ 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