# Name : Liquid surface foam # Description: Water -> Foam -> Water based on pressure # # Author :Richard Sutherland # Directions: # Create three emitters, name your main emitter water, and your secondary emitter foam, and your third emitter water2. # # def onSimulationStep(): pass def onSimulationFrame(): #Variable water = scene.getEmitter("water") #Name of the main fluid emitter. foam = scene.getEmitter("foam") #name of the spray emitter water2 = scene.getEmitter("water2") #name of the spray emitter press_to_foam=-1000 #must be below this to become foam, yes it CAN BE negative. press_to_water=5000 #foam pressuer must be above this to become water again particle_skip=1#Setting this higher reduces foam part_count=0 #loop through water Particles find collision's and emit foam. particles = water.getParticles() for particle in particles: part_count=part_count+1 if(part_count % particle_skip ==0): press=particle.getPressure() if(press < press_to_foam): pos = particle.getPosition() vel = particle.getVelocity() foam.addParticle(pos, vel) water.removeParticle(particle.getId()) #loop through foam particles and go back to water particles = foam.getParticles() for particle in particles: fpress=particle.getPressure() if(fpress > press_to_water): pos = particle.getPosition() vel = particle.getVelocity() water2.addParticle(pos, vel) foam.removeParticle(particle.getId()) def onSimulationBegin(): pass def onSimulationEnd(): pass def onChangeToFrame(): pass