Differential D15285 Diff 52872 source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc
Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc
| Show First 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | static VArray<float> construct_curve_parameter_varray(const bke::CurvesGeometry &curves, | ||||
| if (domain == ATTR_DOMAIN_POINT) { | if (domain == ATTR_DOMAIN_POINT) { | ||||
| Array<float> result = curve_length_point_domain(curves); | Array<float> result = curve_length_point_domain(curves); | ||||
| MutableSpan<float> lengths = result.as_mutable_span(); | MutableSpan<float> lengths = result.as_mutable_span(); | ||||
| threading::parallel_for(curves.curves_range(), 1024, [&](IndexRange range) { | threading::parallel_for(curves.curves_range(), 1024, [&](IndexRange range) { | ||||
| for (const int i_curve : range) { | for (const int i_curve : range) { | ||||
| const float total_length = curves.evaluated_length_total_for_curve(i_curve, | const float total_length = curves.evaluated_length_total_for_curve(i_curve, | ||||
| cyclic[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)); | MutableSpan<float> curve_lengths = lengths.slice(curves.points_for_curve(i_curve)); | ||||
| if (total_length > 0.0f) { | |||||
| const float factor = 1.0f / total_length; | |||||
| for (float &value : curve_lengths) { | for (float &value : curve_lengths) { | ||||
| value *= factor; | 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); | |||||
| } | |||||
| } | |||||
HooglyBoogly: I think this is a bit simpler (and makes it conceptually parallel) | |||||
| } | |||||
| }); | }); | ||||
| return VArray<float>::ForContainer(std::move(result)); | return VArray<float>::ForContainer(std::move(result)); | ||||
| } | } | ||||
| if (domain == ATTR_DOMAIN_CURVE) { | if (domain == ATTR_DOMAIN_CURVE) { | ||||
| Array<float> lengths = accumulated_lengths_curve_domain(curves); | Array<float> lengths = accumulated_lengths_curve_domain(curves); | ||||
| const int last_index = curves.curves_num() - 1; | const int last_index = curves.curves_num() - 1; | ||||
| const int total_length = lengths.last() + curves.evaluated_length_total_for_curve( | const int total_length = lengths.last() + curves.evaluated_length_total_for_curve( | ||||
| last_index, cyclic[last_index]); | last_index, cyclic[last_index]); | ||||
| const float factor = total_length == 0.0f ? 0.0f : 1.0f / total_length; | if (total_length > 0.0f) { | ||||
| const float factor = 1.0f / total_length; | |||||
| for (float &value : lengths) { | for (float &value : lengths) { | ||||
| value *= factor; | 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)); | return VArray<float>::ForContainer(std::move(lengths)); | ||||
| } | } | ||||
| return {}; | return {}; | ||||
| } | } | ||||
| static VArray<float> construct_curve_length_parameter_varray(const bke::CurvesGeometry &curves, | static VArray<float> construct_curve_length_parameter_varray(const bke::CurvesGeometry &curves, | ||||
| const IndexMask UNUSED(mask), | const IndexMask UNUSED(mask), | ||||
| const eAttrDomain domain) | const eAttrDomain domain) | ||||
| ▲ Show 20 Lines • Show All 161 Lines • Show Last 20 Lines | |||||
I think this is a bit simpler (and makes it conceptually parallel)