Procedural API

Context: Procedural
Node group: SimulationSession

This page covers the scene nodes: rigid bodies, cloth and SPH water. The real-time smoke, liquid, particle, ocean and shore nodes are listed on the Physics toolbox page.

A game loop, an interactive tool or a scripted shot needs to act between steps: push a body when it lands, set off a charge on a key press, move a hammer along a path. A SimulationSession is a running scene that a procedural graph drives. It starts from the same SceneDescription the functional nodes build, so the two styles are one model.

1. Lifecycle

Node Inputs (defaults) Does
Start scene, threads 0 builds the engine scene and returns a session at time 0
StepFrame session, framesPerSecond 30 advances one frame, exactly as Simulate does
Advance session, seconds advances any span, in coupling steps
Dispose session releases the engine scene

A session exposes Time (simulated seconds), Frame (frames stepped with StepFrame) and Scene (the description it started from).

Agreement with Simulate. Stepping a session with StepFrame and capturing each frame gives exactly the frames Simulate records for the same scene, bit for bit. Block out a shot interactively, then render it with Simulate and get the same motion.

2. Acting between steps

Actions take effect at the next coupling step.

Node Inputs Does
Detonate session, position, tntKg sets off a charge now; every solver feels the blast and breakable bodies shatter
Push session, body, impulse (N·s) a kick or a thrust
Release session, body a static or kinematic body becomes dynamic
MoveKinematic session, body, position moves a kinematic body; it pushes what it meets
MoveKinematicPose session, body, position, rotation moves and turns a kinematic body over the next coupling step: a hammer, a door, a paddle
AddBody session, body description adds a body to the running scene
RemoveBody session, body takes a body out of the running scene
SetWind session, velocity, gusts 0 changes the wind
SetGravity session, gravity changes gravity
UnpinCloth session, cloth lets go of a cloth's pinned vertices

3. Reading the state

Node Inputs Returns
BodyPosition, BodyRotation, BodyVelocity session, body the body now
BodyNames session every body in the scene, spawned ones included
ClothMesh session, cloth the cloth's surface now
BodiesMesh session every body as one mesh, grounds left out
WaterParticles session, water the water's particles now
Capture session, recordWater true the state as an immutable SimulationFrame, for functional nodes downstream
SavePreview session, path, eye, target, width 960, height 540 renders a CPU preview to PNG and returns the path
Report session what the scene holds and what each solver costs

4. Events

TakeEvents returns the trigger events recorded since the last call, each once, in order. A graph that wants its own logic (a branch on which body was hit) reacts there; reacting inside the step is the job of trigger actions. Use Watch triggers to have the engine record events without acting. See Events and triggers.

5. A typical loop

  1. Start the session from a scene description with a Watch("landed", OnContact("ball", "ground")) trigger.
  2. While Time is under 2 s:
    1. StepFrame at 30 fps.
    2. TakeEvents; for each event whose trigger is landed, Push its body upward by (0, 0, 0.5) N·s.
  3. Read BodiesMesh for rendering, or SavePreview for a quick look.
  4. Dispose.

The same loop as the C# the nodes call:

using var session = SimulationSession.Start(scene);
while (session.Time < 2)
{
    session.StepFrame(30);
    foreach (var e in session.TakeEvents())
        if (e.Trigger == "landed") session.Push(e.Body!, new Vector3d(0, 0, 0.5));
}
var mesh = session.BodiesMesh();

6. Rules

  • A session is not thread-safe: one graph drives it.
  • It owns its engine scene until disposed; dispose it when the graph is done.
  • A loop that only steps and reads poses allocates almost nothing. Capture allocates the frame it returns.
  • Live parameter changes beyond the actions above (a sample's sliders in the Continuum playground) are planned: a later slice can expose a scene's live controls through the session by name.