Builtin Library
README.md
grid.cell_index (procNode)
Which cell of a grid each position falls in, as a Float field: floor((p - min) / cellSide) per axis, flattened x + nx * (y + ny * z); a position outside [0, n) on any axis gives -1.
Built from: field.position, math.*, vector.floor, g.where, g.compare.
Inputs
grid(Grid). The grid whose layout is read: its cells, and the box they fill.position(Field<Vec3>, optional). The positions looked up. Left unwired, it is where each element of the domain the field is evaluated over stands.
Outputs
field(Field<Float>). The cell index of each position, -1 outside the grid.
local air = g.grid.box({ size = vector.create(4, 4, 4), cells = vector.create(4, 4, 4) })
local pts = g.points.grid({ countX = 4, countZ = 4 })
pts.point.cell = g.grid.cell_index({ grid = air })