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:
import random rndNumber = random.uniform(-0.2,0.2) speedLimit = 2.5 emitter = scene.get_PB_Emitter("Container01") collisionObject = scene.getObject("Sphere01") if (len(collisionObject.getCollidingObjects()) > 0): vertices = collisionObject.getVertices() objectVelocity = collisionObject.getVelocity() 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:
polygonObject = scene.getObject("Torus01") polygons = polygonObject.getFaces() vertices = polygonObject.getVertices() vertexPosition = Vector.new(0,0,0) container = scene.get_PB_Emitter("Container01") for polygon in polygons: vertexIndices = polygon.getIndices() vertex0 = vertices[vertexIndices[0]] vertex1 = vertices[vertexIndices[1]] vertex2 = vertices[vertexIndices[2]] vertex0Pos = vertex0.getPosition() vertex1Pos = vertex1.getPosition() vertex2Pos = vertex2.getPosition() vertexPosition = vertex0Pos + vertex1Pos + vertex2Pos vertexPosition.set(vertexPosition.x / 3, vertexPosition.y / 3, vertexPosition.z / 3) container.addParticle(vertexPosition, Vector.new(0,0,0))