Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The result is a little bit strange, because we have to deal with a vector. In the messages window you can see something like this:

<RealFlow Vector object at 0xf74218>

<RealFlow Vector object at 0xf74140>

<RealFlow Vector object at 0xf74218>

 

Vectors are coded within RealFlow and if you want to print out the scalars you have to determine the values individually:

...

Now the output is clearly readable:

  • 0.320292592049 / 0.439999759197 / 0.239609465003
  • 0.250641554594 / 0.439999759197 / 0.311735242605

 

The position of the particle.getNextParticle() statement is of special importance. If it is not inserted correctly, the loop will not stop and will RealFlow freeze.

Another concept of accessing and looping through an emitter’s particles is the “for for ... in“ method. In this case the currently existing particles are written to a list. With a continuous stream of particles this list grows larger with every frame and allocates more memory. Because of the higher memory demand the “for … in” method is often restricted to a certain number of particles. One of the most common approaches is to detect particles colliding with objects. A loop with “for … in” with an events script may look like this:

Code Block
themeEclipse
languagepython
linenumberstrue
emitter       = scene.getEmitter("Circle01")
all_particles = emitter.getParticles() 
 
for single_particle in all_particles:
    do something here

 

The “allall_particles” particles list contains a 1:1 copy of all currently existing particles in your scene and you can loop through them. But sometimes you will only want to restrict operations to a certain amount of particles, maybe the first 1,000 particles. For this purpose, it is possible to set a certain range with a start, stop and step value:

...

Code Block
themeEclipse
languagepython
linenumberstrue
current_particle = all_particles[7] or

current_particle = all_particles[749]

 

The “for … in” and “for … in range” methods are not limited to particles. A list object does not care whether there are particles, objects or vertices stored inside. So these loops can be used with any node, polygon, result and anything else you have inside a list.

Loops are one of the most important methods with RealFlow scripts, especially when you have to deal with particles. There is always a situation where you have to go through all of, or a certain amount of, the particles or objects. For this reason it is highly recommended to become familiar with all different kinds of loops.