How To > Script Particle Flow > Transfer ParticleFlow Particle Motion To Scene Objects |
This simple tutorial provides the basics of moving scene objects using Particle Flow. The objects can be anything from lights through helpers to mesh objects.
In this example, we will move a large number of Atmospheric Gizmos with a Fire Effect assigned to simulate a steaming Teapot.
The ChannelsUsed handler defines the channels to be used by the Script Operator - you cannot get or set particle related values from the particle container without specifying which properties you need access to. This way, Particle Flow does not have to provide the Script Operator with all possible channels (and there can be an arbitrary number of channels in Particle Flow) but only with those that are actually needed. This conserves memory!
The parameter pCont contains the Particle Container.
We want to copy the complete transformation of the particle to the scene object, so we will need access to that channel.
To get an even nicer effect, we will want to read the age of the particle and assign it to the gizmos' radius property to make them grow over time!
The Init handler is used to initialize the Script Operator. The parameter pCont contains the Particle Container.
We define a global variable which will contain an array of the scene objects to be driven by the particles. In this case, we collect all SphereGizmos from the scene using their common base name.
To remove the gizmos from the scene in the first frames of the animation, we move them away from the camera field of view, in this case way down.
The Proceed handler is called every time the Script Operator is evaluated by Particle Flow. It contains the actual body of the script. The parameter pCont contains the Particle Container which contains all particles the Operator is applied to.
First we read the number of particles in the current Event. There can be 0 or millions of particles in the event.
Then we compare the number of particles to the number of collected gizmos. The function amin() returns the smallest value in the array.
Now we will repeat the following code as many times as there are possible particle+gizmo pairs in the scene...
In order to read data from a particle, we must make it the current one. To do so, we assign the index i to the particleIndex property of the particleContainer of the current event. After this, any particle-related queries or assignments will be performed on the i-th particle only!
Now we can assign the transformation matrix of the current i-th particle to the i-th gizmo in the array. Note that because of our smart amin test above, i is guaranteed smaller or equal to both the available particle and gizmo counts...
Finally, we change the radius of the i-th gizmo to 10 units plus twice the age of the i-th particle. 10 is the minimum size of a gizmo (when particleAge is 0), at age of 10 the gizmo's radius will be 30 units etc. You can play with different values to get different cloud behaviors.