Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commite8beb5604c

README.md

sim.spawn (procNode)

A spawn description for a solver: particles born on a set of points at a rate and in bursts, with a starting velocity, a lifetime, a size and the name of the stream they belong to. It owns no particles; wire it into sim.particles' sources, which takes any number of them and reads each at every step. Every number or vector point attribute the points carry (not P, N, id, v, age, life, lifetime, seed, size, stream, alive or slot) rides in rows as stamp_<name>, and sim.particles stamps it onto each particle born at the point.

  • rate is births a second, animatable; perMeter is births for every metre the points travel, so a trail behind a mover has the same density at any speed and frame rate, a source that stands still births nothing by it, and the births of a single jump are bounded by the solver's capacity. The two add.
  • The steps between two presents are born where the points stood at each step's time, so a stream from a fast mover is a continuous line rather than a clump at each present.
  • bursts is a list of births all at once. An entry is { x = time, y = count }, or a record of time, count (a number, or { x = fewest, y = most } for a different number at each firing; minCount and maxCount say the same), cycles (how many times it fires, default 1), interval (seconds between firings) and probability (the share of firings kept, default 1). Times are in simulation seconds. An entry carrying any other key is refused, naming it.

Inputs

  • points (Points): where particles are born: each birth picks one of these points.
  • rate (Float, default 20, min 0): particles born per second of simulation time, spread over the points. Animatable; the solver reads it at each of its steps.
  • perMeter (Float, default 0, min 0): particles born for every metre the points travel, summed over the points. The distance is measured between one present and the next, for the points that keep their id (or, with none, their place in the set), plus the length of any moved attribute the points carry. Animatable.
  • bursts (List<Record>, optional): extra births all at once, as above.
  • lifetime (Vec2, default (1, 2)): how long a particle lives in seconds, drawn between x and y for each one.
  • velocity (Vec3, default (0, 1, 0)): the velocity every particle is born with.
  • jitter (Float, default 0, min 0): a random velocity up to this length added at birth, in any direction.
  • speed (Vec2, default (0, 0)): a speed drawn between x and y for each particle, taken along the Vec3 point attribute along names and added to velocity.
  • along (String, default "N"): the Vec3 point attribute speed is taken along, read at each particle's birth point. A speed other than zero needs the points to carry it, and the cook refuses points that do not.
  • size (Vec2, default (0.1, 0.1)): a particle's size, drawn between x and y for each one.
  • stream (String, default "main"): the name of the stream this source's particles belong to; sim.particles gives each particle the index of its source as stream and lists the names in its detail labels.stream.
  • seed (Float, default 0): which of the possible sequences of births this source makes.
  • order (String, default "random"): "random" draws one point for every birth; "inTurn" takes the points one after another.

Outputs

  • source (Record): what sim.particles reads: kind ("sim.spawn"), points, rows (the points as the solver reads them: P where they stand, A the direction along names, M any moved attribute, I each point's id or place, each zero where the points carry none, and stamp_<name> for each attribute stamped onto the particles), rate, perMeter, bursts (the firings the entries state, each { x = time, y = count }), lifetime, velocity, jitter, speed, along, size, stream, seed and inTurn.

Example

local emitter = g.points.grid({ countX = 1, countZ = 1, y = 1 })
local source = g.sim.spawn({
    points = emitter,
    rate = 30,
    bursts = { { time = 0, count = 50 } },
    lifetime = { x = 1, y = 2 },
    velocity = vector.create(0, 3, 0),
    jitter = 1,
    stream = "sparks",
})
local sim = g.sim.particles({ sources = { source }, gravity = vector.create(0, -9.8, 0) })