Versions Compared

Key

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

...

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:

...

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.