Geometry Nodes: Multithread curve resample node
Optimize the node for the case of many splines. In a test file with 14000 splines, the node is 3x faster (72ms to 24ms) on an 8 core CPU.
This commit is contained in:
@@ -138,19 +138,28 @@ static SplinePtr resample_spline(const Spline &input_spline, const int count)
|
||||
static std::unique_ptr<CurveEval> resample_curve(const CurveEval &input_curve,
|
||||
const SampleModeParam &mode_param)
|
||||
{
|
||||
std::unique_ptr<CurveEval> output_curve = std::make_unique<CurveEval>();
|
||||
Span<SplinePtr> input_splines = input_curve.splines();
|
||||
|
||||
for (const SplinePtr &spline : input_curve.splines()) {
|
||||
if (mode_param.mode == GEO_NODE_CURVE_SAMPLE_COUNT) {
|
||||
BLI_assert(mode_param.count);
|
||||
output_curve->add_spline(resample_spline(*spline, *mode_param.count));
|
||||
}
|
||||
else if (mode_param.mode == GEO_NODE_CURVE_SAMPLE_LENGTH) {
|
||||
BLI_assert(mode_param.length);
|
||||
const float length = spline->length();
|
||||
const int count = std::max(int(length / *mode_param.length), 1);
|
||||
output_curve->add_spline(resample_spline(*spline, count));
|
||||
}
|
||||
std::unique_ptr<CurveEval> output_curve = std::make_unique<CurveEval>();
|
||||
output_curve->resize(input_splines.size());
|
||||
MutableSpan<SplinePtr> output_splines = output_curve->splines();
|
||||
|
||||
if (mode_param.mode == GEO_NODE_CURVE_SAMPLE_COUNT) {
|
||||
threading::parallel_for(input_splines.index_range(), 128, [&](IndexRange range) {
|
||||
for (const int i : range) {
|
||||
BLI_assert(mode_param.count);
|
||||
output_splines[i] = resample_spline(*input_splines[i], *mode_param.count);
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (mode_param.mode == GEO_NODE_CURVE_SAMPLE_LENGTH) {
|
||||
threading::parallel_for(input_splines.index_range(), 128, [&](IndexRange range) {
|
||||
for (const int i : range) {
|
||||
const float length = input_splines[i]->length();
|
||||
const int count = std::max(int(length / *mode_param.length), 1);
|
||||
output_splines[i] = resample_spline(*input_splines[i], count);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
output_curve->attributes = input_curve.attributes;
|
||||
|
Reference in New Issue
Block a user