Versions Compared

Key

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

...

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:

Code Block
languagepy
# 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)

...

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

Code Block
# Get the "Torus01" object and its polygons and vertices
# Define a null vector and get the stands 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))