Working with Frames and Times
 
 
 

Getting Time Data

There are some nodes in the Get Data category that return time data:

  • Current Frame returns the local frame number, or the global frame if Global is true.

  • Current Time returns the local time in seconds, or the global time if Global is true.

  • Simulation Step returns the length of a frame in seconds. It is equivalent to getting PlayControl.Rate and doing the math yourself.

During a simulation, the local time is the time for which the simulation has been active. The first frame that the simulation is active is 0, and corresponds to the initial state.

The global frame is always the value of the current frame in the playback panel.

Age

The Age attribute of particles is in seconds, and is automatically incremented every frame by the simulation environment. The Age of new points is automatically randomized to a fraction of a frame by the Emitter compounds.

The Clone Point node and compounds that include it (such as the Spawning compounds) copy the Age attribute. If you want newly cloned points to have a different age, you must set it using the On Creation or Execute on Spawn ports.

Sub-frame Simulations

Simulations are calculated on a per-frame basis. However, a frame can be a long time, especially when dealing with particle emissions and collisions. In many situations, it becomes necessary to consider slices of time smaller than a single frame.

The SimulatedFrameFraction stores the portion of a frame for which a point has already been simulated. The Simulate Particles node affects a particle for a length of time equal to (1 – SimulatedFrameFraction)*SimulationStep, and then set the attribute to 1.0 so that the particle is unaffected by other Simulate Particles nodes for the rest of the frame. SimulatedFrameFraction is reset to zero at the beginning of each frame.

The Emitter compounds automatically initializes SimulatedFrameFraction and sets it to (1 – Age/SimulationStep) so that on its first frame of existence, a particle only moves for a distance proportional to its age. As a result, it appears as if particles have been emitted continuously throughout the frame instead of all at once.

You can set the SimulatedFrameFraction attribute directly. For example, suppose you use the Basic Collide node to test for collision with a geometry. If a point will collide, you can store the old value of SimulatedFrameFraction in a custom attribute, say OldSFF. You can then set SimulatedFrameFraction to the value of Hit Frame Fraction returned by the Basic Collide node and simulate up to the moment of collision. After that, set SimulatedFrameFraction to OldSFF + Hit Frame Fraction before changing states or doing something else for the rest of the frame.

The Get Remaining Frame Fraction and Get Remaining Seconds in Frame compounds can also be useful when working with sub-frame simulations.