Changing Particle Attributes

When you are working with particles, the get and set instructions are slightly different. A node’s parameters are always called with the getParameter(string) command, but particles do not have attributes like friction, rotation, or roughness. They are described with density, position, velocity, viscosity, and so on. To distinguish these settings from a node’s basic properties, the attributes can be accessed directly with appropriate functions:

vector getVelocity() -> setVelocity(vector)

 

With particles you do not need an introducing argument specifying the desired parameter, because that is already implemented in the statement and you only have to hand over the value with the correct data type. Some properties, like velocity, normals or positions, are not only valid for particles. The getVelocity(vector) statement can be used for objects and vertices, for example, but it is not possible to apply setVelocity(vector) to an object.

By using "get" you can read out a lot of values and attributes, but the corresponding list of set instructions is rather short. Most of a particle’s attributes either directly influence the solver’s stability, or it simply makes no sense to change them on a per-particle base. These are the four attributes you can directly change with “set” instructions: 

  • setExternalForce(vector)
  • setPosition(vector)
  • setUV(vector)
  • setVelocity(vector)

 

The “get” commands, such as getDensity(float) or getNeighbors(float), are actually only used for comparisons or to trigger other functions and routines:

# Write this part to Simulation Events > Frames > FramesPre

frame   = scene.getCurrentFrame()
emitter = scene.get_PB_Emitter("Circle01")

if (frame == 125):
    emitter.setParameter("Speed", 0.0)

# Write this part to Simulation Events > Steps > StepsPre

total_mass = 0.0
emitter    = scene.get_PB_Emitter("Circle01")
particle   = emitter.getFirstParticle()

while (particle):
 pressure   = particle.getPressure()
 mass       = particle.getMass()
 total_mass = total_mass + mass

 if((pressure >= 50) and (total_mass >= 2000)):
     new_velocity = Vector.new(0.0, 0.0, 0.0)
     particle.setVelocity(new_velocity)

 particle = particle.getNextParticle()

The particles in this case behave a little bit like liquid wax that is cooling down and the zero velocity statement gives you an interesting effect.