Versions Compared

Key

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

...

Code Block
themeEclipse
languagepython
linenumberstrue
import random


# Get the global values from batch script

source_name = scene.getGlobalVariableValue("source")
target_name = scene.getGlobalVariableValue("target")
threshold   = scene.getGlobalVariableValue("threshold")
tolerance   = scene.getGlobalVariableValue("tolerance")
rndValue    = random.uniform(-tolerance / 2, tolerance / 2)
source      = scene.get_PB_Emitter(source_name)
target      = scene.get_PB_Emitter(target_name)

 
# Go through all particles, compare velocity and shift them to the target emitter

particle = source.getFirstParticle()
while (particle):
 
    if (particle.getVelocity().module() >= threshold + rndValue):
        pos = particle.getPosition()
        vel = particle.getVelocity()
        pid = particle.getId()

       target.addParticle(pos,vel)
       source.removeParticle(pid)
 
    particle = particle.getNextParticle()