Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commitdd348ac6c3

README.md

sim

Simulation: what a solver's particles are born from, what pushes them and what they bounce off, and sim.particles, the particle solver.

These are the sim context's nodes. What one of them makes is read by the solver at every step, so it is wired into another sim node or into an input that opens sim — sim.particles' sources, forces and colliders. Wired anywhere else, procgen.validate reports it and the cook refuses it.

The definitions live in proc.ops.sim; this pack is what puts them in the node registry, so procgen.searchNodes("", { pack = "sim" }) lists the family and procgen.describeNode("op.<id>") describes any one of them.

Nodes

  • sim.spawn — a spawn description: particles born on a set of points at a rate and in bursts, with a starting velocity, a lifetime, a size and a stream name.

  • sim.force — a force the solver applies at every step, from any Vec3 field evaluated where each particle is: as an acceleration (mode = "acceleration", scaled by strength), or as a velocity each particle is pulled toward at strength a second (mode = "velocity"). Wind is a wind field and drag is still air, both as velocities.

  • sim.collider — a plane, a sphere or a box the particles bounce off.

  • sim.scene_colliders — the scene's collision environment: every box, sphere and capsule physics collider that is not a sensor, turned and moving with its entity, solid from every side, and read where it stands in the graph's space at every step. Its within takes only the colliders near its center; a solver takes at most 128 shapes.

    Every shape is met along the whole of each step's move, so a fast particle does not pass through a thin one.

  • sim.particles — the particle solver, a geometry node: every particle from every spawn in one geometry on the GPU, stepped over the graph's timeline under the forces and against the colliders, output as the particles alive now.

local emit = g.op.points.sphere({ radius = 0.1, count = 16 })
local src = g.op.sim.spawn({ points = emit, rate = 300, speed = { x = 3, y = 6 } })
local swirl = g.op.sim.force({ field = g.op.field.curl({ frequency = 0.8, amplitude = 4 }) })
local walls = g.op.sim.scene_colliders({ bounce = 0.3 })
local sparks = g.op.sim.particles({ sources = { src }, forces = { swirl }, colliders = { walls },
    gravity = { x = 0, y = -9.8, z = 0 } })
return { points = sparks.points }

sim.particles answers a record of its outputs: points (the particles alive now), births, deaths and hits.