Adding Particles

During Simulation

Add the script to Simulation Flow (Ctrl/Cmd + F2) > StepsPre.

The script creates particles from the "Sphere01" (active rigid body) object's vertices when it is colliding with other objects. The object's velocity is transferred to the particles, but must be greater or equal to the a given speed limit. When the object rests no particles will be emitted.

New particles are being added to a standard particle fluid "Container01" node. Be aware that the number of particles can grow quickly, and we recommend using low-resolution objects for this example:

# Load Python's random number generator
import random

# Create random number and define a threshold ("speedLimit")
rndNumber       = random.uniform(-0.2,0.2)
speedLimit      = 2.5
 
# Get the standard particle emitter "Container01" and its collision object "Sphere01"
emitter         = scene.get_PB_Emitter("Container01")
collisionObject = scene.getObject("Sphere01")

# Check if there is a collision object
# Since the scene only contains one collision object "Sphere01" no further separation is required
if (len(collisionObject.getCollidingObjects()) > 0):
 
	# Get the "Sphere01" node's vertices and its velocity
	vertices       = collisionObject.getVertices()
	objectVelocity = collisionObject.getVelocity()

	# Loop through every vertex and compare its velocity against "speedLimit"
	# If the vertex's velocity is greater than or equal to "speedLimit", change the point's velocity
	for vertex in vertices:
		if (objectVelocity.module() >= speedLimit):
			vertexVelocity = vertex.getVelocity()
			vertexVelocity.scale(1.2 + rndNumber)
			emitter.addParticle(vertex.getPosition(), vertexVelocity)

As Batch Process

Add this script to a "Batch Script" editor (F10) and execute it with Script > Run.

Get a torus object's polygons and the three vertices of each polygon. Then, calculate each polygon's midpoint and place a particle there:

# Get the "Torus01" object and its polygons and vertices
# Define a null vector and get the standard particle node "Container01"
polygonObject   = scene.getObject("Torus01")
polygons        = polygonObject.getFaces()
vertices        = polygonObject.getVertices()
vertexPosition  = Vector.new(0,0,0)
container       = scene.get_PB_Emitter("Container01")

# Loop through every polygon and get its associated 3 vertices
for polygon in polygons:
    vertexIndices  = polygon.getIndices()
    vertex0        = vertices[vertexIndices[0]]
    vertex1        = vertices[vertexIndices[1]]
    vertex2        = vertices[vertexIndices[2]]

	# Get the 3 vertex positions
    vertex0Pos     = vertex0.getPosition()
    vertex1Pos     = vertex1.getPosition()
    vertex2Pos     = vertex2.getPosition()

	# Add all position vectors and calculate the average position (=polygon's midpoint)
    vertexPosition = vertex0Pos + vertex1Pos + vertex2Pos
    vertexPosition.set(vertexPosition.x / 3, vertexPosition.y / 3, vertexPosition.z / 3)

	# Place a new particle at "vertexPosition" with velocity 0
    container.addParticle(vertexPosition, Vector.new(0,0,0))