Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 13 Next »

Batch Script Part

 

emitterList = []
colourList  = ["Red","Orange","Purple","White","Yellow"]
rgbList     = ((200,0,25),(255,150,0),(180,0,180),(255,255,255),(255,225,0))
emitters    = scene.get_PB_Emitters()

for emitter in emitters:
    emitterList.append(emitter.getName())

guiForm = GUIFormDialog.new()

guiForm.addListField("Source Emitter", emitterList, 0)
guiForm.addListField("Target Emitter", emitterList, 1)
guiForm.addListField("Colour", colourList, 3)
guiForm.addFloatField("Threshold Value", 2.0)
guiForm.addFloatField("Tolerance", 1.0)
guiForm.addFloatField("Speed", 2.0)

if (guiForm.show() == GUI_DIALOG_ACCEPTED):
    emitter1  = guiForm.getFieldValue("Source Emitter")
    emitter2  = guiForm.getFieldValue("Target Emitter")
    colour    = guiForm.getFieldValue("Colour")
    threshold = guiForm.getFieldValue("Threshold Value")
    tolerance = guiForm.getFieldValue("Tolerance")
    speed     = guiForm.getFieldValue("Speed")

# Process the source emitter's properties and set speed to the given value

source       = scene.getEmitter(emitterList[emitter1])
s_resolution = source.getParameter("Resolution")

source.setParameter("Speed", speed)
source.setParameter("Color", Vector.new(128,128,128))


# Attach colour, parameters and set speed/volume to 0.0 

e_colour = rgbList[colour]
rgb      = Vector.new(e_colour[0], e_colour[1], e_colour[2])
target   = scene.getEmitter(emitterList[emitter2])

target.setParameter("Color", rgb)
target.setParameter("Resolution", s_resolution)
target.setParameter("Speed", 0.0)
target.setParameter("Volume", 0.0)


# Define the global variables

scene.setGlobalVariableValue("source", emitterList[emitter1])
scene.setGlobalVariableValue("target", emitterList[emitter2])
scene.setGlobalVariableValue("threshold", threshold)
scene.setGlobalVariableValue("tolerance", tolerance)
 

# Reset and start the simulation automatically, abort with ESC!

scene.reset()
scene.simulate(0,200)

 

2. The simulation events (StepPre) part:

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()
  • No labels