Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commitdd348ac6c3

README.md

data

The operations a new node is built from. Each one is a single pass over a whole class of elements on the device. Processing data is a graph of these: a field computes a value per element, and these ops move it, fold it, and keep or reorder the elements.

procgen.searchNodes("", { pack = "data" }) lists the family and procgen.describeNode("op.<id>") describes any one of them.

Ops

  • attribute.gather — each element reads a column from the element its index names, in this geometry or in a source geometry. Use it to read a neighbour or a parent, or to copy values across by id.
  • attribute.scatter — each element sends a column to the element its index names. Every receiving element folds what reached it (sum, mean, min or max), and an element nothing reached holds fill. Use it for deposits, per-cell totals and group sizes.
  • attribute.promote — moves a column between points, corners, edges, faces and the whole geometry (detail). Moving to fewer elements folds; moving to more copies.
  • attribute.accumulate — a running or total fold of a column, over the whole class or within the groups that by names.
  • elements.keep — keeps the points or faces whose value is not 0, with every column they carry.
  • elements.sort — puts the points or faces in the order of a value.

A threshold filter is field.compare into elements.keep; this one keeps about half the points:

local pts = g.points.grid({ countX = 8, countZ = 8 })
local coin = g.op.field.random({})
local kept = g.op.elements.keep({ geometry = pts, keep = g.op.field.compare({ a = coin, b = 0.5, op = "gt" }) })

A total per group, standing on every member: each face of a mesh holds how many faces its island has.

local parts = g.op.topology.islands({ geometry = g.mesh.box({}) })
local ones = g.op.attribute.set({ domain = parts.geometry, class = "primitive", name = "one", value = 1 })
local island = g.op.field.attribute({ class = "primitive", name = "island" })
local counted = g.op.attribute.accumulate({ geometry = ones, by = island, name = "one", class = "primitive",
    mode = "total", as = "islandFaces" })