Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDalai Felinto <dalai@blender.org>2022-06-24 13:42:52 +0300
committerDalai Felinto <dalai@blender.org>2022-06-24 16:36:31 +0300
commitf1d191120f4f1d762369b19bdbf8d9be29000d77 (patch)
tree0fee78aef360490800a06817db36dd2cd013bba7 /source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc
parentad8add5f0cbe1b5abb85a6cf510e52b66de273e9 (diff)
Fix T99130: Spline factor gets messed up if one hair is too short
In the cases where length is zero, we simply equally distribute the value based on the control point/curve index. Differential Revision: https://developer.blender.org/D15285
Diffstat (limited to 'source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc')
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc32
1 files changed, 26 insertions, 6 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc
index ae2b4fd779d..b98541e3446 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc
@@ -119,10 +119,20 @@ static VArray<float> construct_curve_parameter_varray(const bke::CurvesGeometry
for (const int i_curve : range) {
const float total_length = curves.evaluated_length_total_for_curve(i_curve,
cyclic[i_curve]);
- const float factor = total_length == 0.0f ? 0.0f : 1.0f / total_length;
MutableSpan<float> curve_lengths = lengths.slice(curves.points_for_curve(i_curve));
- for (float &value : curve_lengths) {
- value *= factor;
+ if (total_length > 0.0f) {
+ const float factor = 1.0f / total_length;
+ for (float &value : curve_lengths) {
+ value *= factor;
+ }
+ }
+ else {
+ /* It is arbitrary what to do in those rare cases when all the points are
+ * in the same position. In this case we are just arbitrarily giving a valid
+ * value in the range based on the point index. */
+ for (const int i : curve_lengths.index_range()) {
+ curve_lengths[i] = i / (curve_lengths.size() - 1.0f);
+ }
}
}
});
@@ -135,9 +145,19 @@ static VArray<float> construct_curve_parameter_varray(const bke::CurvesGeometry
const int last_index = curves.curves_num() - 1;
const int total_length = lengths.last() + curves.evaluated_length_total_for_curve(
last_index, cyclic[last_index]);
- const float factor = total_length == 0.0f ? 0.0f : 1.0f / total_length;
- for (float &value : lengths) {
- value *= factor;
+ if (total_length > 0.0f) {
+ const float factor = 1.0f / total_length;
+ for (float &value : lengths) {
+ value *= factor;
+ }
+ }
+ else {
+ /* It is arbitrary what to do in those rare cases when all the points are
+ * in the same position. In this case we are just arbitrarily giving a valid
+ * value in the range based on the curve index. */
+ for (const int i : lengths.index_range()) {
+ lengths[i] = i / (lengths.size() - 1.0f);
+ }
}
return VArray<float>::ForContainer(std::move(lengths));
}