babylon.quarks - v1.0.0
    Preparing search index...

    Interface Behavior

    A behavior changes particles over time; a particle system runs a list of them every simulation step. Each method is called by the host (the system that owns the behavior), in this order:

    1. initialize once per particle, when it is emitted. The particle is already in the system's pool, placed and given its start values by the emitter shape, and converted to the simulation space; particleSystem is the system it belongs to. A behavior that reads a per-particle random sample starts its generators on particle.memory here.
    2. frameUpdate once per step, with the step's length, just before this behavior updates its particles (after the behaviors before it have updated theirs). Per-step work (decomposing the emitter's transform, advancing a time offset) belongs here.
    3. update once per live particle, or updateAll once for the whole pool when it is implemented. The particle's age is the age at the start of the step; the host adds delta and integrates the velocity after every behavior has run. Over-life curves are read at the age the step ends at, stepEndAge (or stepEndLife as a fraction of the life), the age the particle is drawn at, as Unity reads them.
    4. reset when the system restarts, before it emits again: state accumulated across steps goes back to how it was before the first one.

    Randomness is drawn through random() from quarks.core's util/random, never Math.random, so a host that runs its steps inside setRandomSource (or withRandomSource) with a seeded generator replays the same effect, as babylon.quarks does for a system with a seed. Any other state a behavior keeps must be derived from its settings, so a clone() or a saved and reloaded copy behaves the same.

    toJSON writes the behavior's settings as plain data, the type and every field (a few leave out a zero or empty value); BehaviorTypes[type].loadJSON reads it back, and reads a missing field as its default. An effect file holds BehaviorToJSON, which leaves out the fields at their defaults. The params of that entry list the fields an editor shows.

    interface Behavior {
        type: string;
        clone(): Behavior;
        frameUpdate(delta: number): void;
        initialize(particle: Particle, particleSystem: IParticleSystem): void;
        reset(): void;
        toJSON(): BehaviorJSON;
        update(particle: Particle, delta: number): void;
        updateAll?(particles: Particle[], count: number, delta: number): void;
    }

    Implemented by

    Index
    type: string

    The name the behavior is registered under in BehaviorTypes.

    • A copy with the same settings that shares nothing mutable with this one.

      Returns Behavior

    • Called once per step before this behavior updates the particles, with the step's length in seconds.

      Parameters

      • delta: number

      Returns void

    • Called once per particle when it is emitted; see the interface's description for when.

      Parameters

      Returns void

    • Called when the system restarts (not when a looping system starts its next loop): forget state accumulated across steps, so the replay starts as the first play did.

      Returns void

    • The behavior's settings as plain data, with its type; see the interface's description.

      Returns BehaviorJSON

    • Called once per live particle per step, with the step's length in seconds.

      Parameters

      Returns void

    • Optional bulk form of update, applied to particles[0..count).

      The per-particle update is reached through one call site shared by every behavior type, which leaves it megamorphic: V8 can neither inline it nor specialise the generator calls inside. A behavior that implements this instead gets one call per frame and a loop it owns, where those calls are monomorphic. Implementations must skip dead particles (age >= life) exactly as the per-particle path does, and must produce identical results.

      Behaviors that do not implement it keep working unchanged. A subclass that overrides update but not updateAll has its update called, not the inherited updateAll.

      Parameters

      • particles: Particle[]
      • count: number
      • delta: number

      Returns void