Page MenuHome

Geometry Nodes: Add Input Spline Length
ClosedPublic

Authored by Johnny Matthews (guitargeek) on Sep 29 2021, 9:18 PM.

Details

Summary

This is an input node that fills a field with the length of each spline.

Demo File:

Diff Detail

Repository
rB Blender

Event Timeline

Johnny Matthews (guitargeek) requested review of this revision.Sep 29 2021, 9:18 PM
Johnny Matthews (guitargeek) created this revision.
Hans Goudey (HooglyBoogly) requested changes to this revision.Sep 29 2021, 9:29 PM
Hans Goudey (HooglyBoogly) added inline comments.
source/blender/nodes/geometry/nodes/node_geo_input_spline_length.cc
47–49

I would suggest a slightly different virtual array implementation. Currently this requires calculating the length of all splines, regardless of the IndexMask. A virtual array that only calculated the necessary elements would be helpful here, since each calculation isn't trivial if the result has not already been cached on the spline:

Something like this should work. Though the constructors are a bit complex, it's also relatively simple to read.

Span<SplinePtr> splines = curve.splines();
auto length_fn = [splines](int i) { return splines[i]->length(); };
return &scope.construct<
    fn::GVArray_For_EmbeddedVArray<float, VArray_For_Func<float, decltype(length_fn)>>>(
    splines.size(), splines.size(), length_fn);
51

This should also handle the point domain. In that case, it can use the curve component's attribute_try_adapt_domain method.

This revision now requires changes to proceed.Sep 29 2021, 9:29 PM
Johnny Matthews (guitargeek) retitled this revision from Geometry Nodes: Add Input Spline Length (WIP) to Geometry Nodes: Add Input Spline Length.
Johnny Matthews (guitargeek) edited the summary of this revision. (Show Details)

Looks good to me! But maybe Jacques has some input.

Remove unused function

Would be good if you could add a simple example file/screenshot that shows how this could be used.

source/blender/nodes/geometry/nodes/node_geo_input_spline_length.cc
51

This first std::move is not necessary.

This revision is now accepted and ready to land.Sep 30 2021, 7:12 PM

Aside from Jacques comment, I think this is ready for committing.

Johnny Matthews (guitargeek) edited the summary of this revision. (Show Details)

Minor code change.