Builtin Library
README.md
attribute.scatter
Each element sends a column to the element its index names, and every element that receives folds what reached it: their sum, mean, least or greatest. Element i of the source's class sends name to element index(i) of this geometry's to class; an element nothing reached holds fill. What deposits particles into cells, adds up the weight on each point, or counts the members of each group. The same answer every run.
Inputs
geometry(Geometry). What receives. A copy comes out with the folded values underason itstoclass.index(Field | Float). For each sending element, the element it sends to: a whole number, 0 for the first. An index naming no element sends nowhere.source(Geometry, optional). What sends. Left empty, the geometry sends to itself.name(String). Default"". The column sent. A name the sending class does not carry is refused.class(one of edge, point, vertex, primitive). Default"point". Which elements send: the class the index is read over.to(one of "", edge, point, vertex, primitive). Default"". Which class of the geometry receives. Left empty it isclass.op(one of sum, mean, min, max). Default"sum". How an element folds what reached it: added up, averaged, the least or the greatest.fill(Float | Vec2 | Vec3 | Vec4). Default0. What an element nothing reached holds.as(String). Default"". The name the folded values are written under. Left empty it isname.
Outputs
geometry: the receiving geometry with the folded values underas(orname) on itstoclass, one per element of that class.
Example
local points = g.points.grid({ countX = 4, countZ = 1, spacing = 1 })
local numbered = g.attribute.set({ geometry = points, name = "n", value = g.element.id * 1.0 })
local most = g.attribute.scatter({ geometry = numbered, index = g.math.floor(g.element.id / 2), name = "n", op = "max", fill = -1, as = "most" })
Points 0 and 1 send to point 0, points 2 and 3 to point 1: most holds 1, 3, -1, -1.