Page MenuHome

Geometry Nodes: Add Selection Input to Attribute Statistics Node
ClosedPublic

Authored by Johnny Matthews (guitargeek) on Dec 9 2021, 12:02 AM.

Details

Summary

Add a boolean field input to Attribute Statistics to determine if the data at that index should be computed in the output.

Demo File:

Diff Detail

Repository
rB Blender

Event Timeline

Johnny Matthews (guitargeek) requested review of this revision.Dec 9 2021, 12:02 AM
Johnny Matthews (guitargeek) created this revision.
Johnny Matthews (guitargeek) planned changes to this revision.Dec 9 2021, 1:41 AM
Johnny Matthews (guitargeek) retitled this revision from Geometry Nodes: Add Selection Input to Attribute Statistics Node to Geometry Nodes: Add Selection Input to Attribute Statistics Node - WIP.
Johnny Matthews (guitargeek) edited the summary of this revision. (Show Details)

This is glitchy in some cases. Needs work.

Johnny Matthews (guitargeek) retitled this revision from Geometry Nodes: Add Selection Input to Attribute Statistics Node - WIP to Geometry Nodes: Add Selection Input to Attribute Statistics Node.Dec 9 2021, 2:34 AM
Johnny Matthews (guitargeek) edited the summary of this revision. (Show Details)
  • Merge branch 'master' into statistics_selection
  • Combine Evaluators
  • Cleanup
  • set_selection and get_evaluated_selection_as_mask
Hans Goudey (HooglyBoogly) requested changes to this revision.Dec 14 2021, 6:38 PM
Hans Goudey (HooglyBoogly) added inline comments.
source/blender/nodes/geometry/nodes/node_geo_attribute_statistic.cc
35

Selection inputs should go below the geometry input.

163

I don't think there's any need to initialize the values.

168

No need for a temporary array here if it's just going to be copied into the data vector after.

176

I think these could be simplified by slicing data beforehand, then iterating over selection.index_range() rather than keeping track of a "position"

185

I'm not sure how resizing this *after* adding the data to it works, I think data could just be an array instead, since the size is known beforehand.

242

Don't reuse a variable and give it a different meaning.

This revision now requires changes to proceed.Dec 14 2021, 6:38 PM

Don't have any other comments besides what Hans said already.

Johnny Matthews (guitargeek) marked 3 inline comments as done.Dec 14 2021, 7:32 PM
Johnny Matthews (guitargeek) added inline comments.
source/blender/nodes/geometry/nodes/node_geo_attribute_statistic.cc
185

Maybe I'm misunderstanding something then. Here was my logic:

  • Make a temp array large enough for all the source data
  • Evaluate the source data into the temp array
  • get the mask
  • use the mask to only copy the selected source data into the Vector that will have calculations done on it.
  • Since there may now be room at the end of this vector, chop it off to the right length
  • Move along to the stats.
  • Several cleanup changes
source/blender/nodes/geometry/nodes/node_geo_attribute_statistic.cc
185

That works, but there's no need to evaluate into an array directly, you can just use const VArray<float3> &component_data = data_evaluator.get_evaluated<float3>()

And you resized the vector to total_size earlier in the function, there shouldn't be any extra room at the end. (You never call append)

Johnny Matthews (guitargeek) marked 2 inline comments as done.
  • Cleaner use of data structures.
Hans Goudey (HooglyBoogly) requested changes to this revision.Dec 14 2021, 9:32 PM

Closer!

source/blender/nodes/geometry/nodes/node_geo_attribute_statistic.cc
158–167

Maximum size is never used, so this calculation could be completely removed.

171

Moving from the selection field won't work if there is more than one component

176

I still think this would be an improvement.

177

I doesn't seem correct to subtract one here, what's the reasoning for that?

263

It looks simpler to just skip this variable and call data.size() below.

This revision now requires changes to proceed.Dec 14 2021, 9:32 PM
source/blender/nodes/geometry/nodes/node_geo_attribute_statistic.cc
177

just a severe case of copy-and-paste-itis

Looks good to me now :)

source/blender/nodes/geometry/nodes/node_geo_attribute_statistic.cc
176

const (same with the other)

This revision is now accepted and ready to land.Dec 15 2021, 5:20 AM