Type Alias

SCNParticleModifierBlock

The signature for blocks called by SceneKit to modify particle properties on each frame of simulation, used by the addModifierForProperties:atStage:withBlock: method.

Declaration

typedef void (^SCNParticleModifierBlock)(void * _Nonnull *data, size_t *dataStride, NSInteger start, NSInteger end, float deltaTime);

Discussion

The block takes the following parameters:

data

An array of floating-point values containing stripes of property data for the system’s particles. The width and format of each data stripe depend on the properties you specify when calling the addModifierForProperties:atStage:withBlock: method.

dataStride

An array identifying the offset, in bytes, of each property’s value in the data stripe for each particle. The order of offsets in this array corresponds to the order of the properties array you specify when calling the addModifierForProperties:atStage:withBlock: method.

start

The index of the first particle’s data stripe in the data array.

end

The index of the last particle’s data stripe in the data array.

deltaTime

The elapsed time, in seconds, since the last frame of simulation.

Use this block to change properties of individual particles on each frame of simulation.

The following example illustrates setting up a modifier block that alters particle’s position and velocity:

[system addModifierForProperties:@[SCNParticlePropertyPosition,
                                   SCNParticlePropertyVelocity]
                         atStage:SCNParticleModifierStagePostDynamics
                       withBlock:^(void **data, size_t *dataStride, NSInteger start, NSInteger end, float deltaTime) {
                           // For each particle to be processed,
                           // calculate pointers in the data to each property's value:
                           for (NSInteger i = start; i < end; ++i) {
                               // SCNParticlePropertyPosition (float3)
                               float *pos = (float *)((char *)data[0] + dataStride[0] * i);
                               // pos[0..2] are the xyz components of the particle's position.
 
                               // SCNParticlePropertyVelocity (float3)
                               float *vel = (float *)((char *)data[1] + dataStride[1] * i);
                               // vel[0..2] are the xyz components of the particle's position.
 
                               // Now, compute a new position and velocity (not shown).
                           }
                       }];

See Also

Modifying Particles Over Time

propertyControllers

A dictionary that optionally associates particle properties with objects that animate a property’s value for each particle.

- addModifierForProperties:atStage:withBlock:

Adds a block that modifies particle properties, to be executed each time SceneKit renders a frame.

- removeModifiersOfStage:

Removes particle modifier blocks for the specified stage of the particle simulation.

- removeAllModifiers

Removes all particle modifier blocks associated with the particle system.

SCNParticleProperty

Keys identifying properties of individual particles, used by the propertyControllers dictionary and the handleEvent:forProperties:withBlock: and addModifierForProperties:atStage:withBlock: methods.

SCNParticleModifierStage

Stages of SceneKit’s particle simulation process into which you can insert modifier blocks, used by the addModifierForProperties:atStage:withBlock: method.