Add Foam/bubbles per Object

Discussion about scripting with Python
fatsumo
Posts: 44
Joined: Tue May 15, 2007 11:24 am
Contact:

Add Foam/bubbles per Object

Postby fatsumo » Tue Oct 09, 2007 9:54 am

yeah sure,
it's probably a real bodge way of doing it, and i've ripped apart a few examples,
but it did the job :)

Code: Select all

from random import randint
#--------------------------------------------------
# Function: onSimulationStep
#--------------------------------------------------

def onSimulationStep():
   liquid = scene.getEmitter("Liquidc")
   foam = scene.getEmitter("Foamb")
    liquid2 = scene.getEmitter("liquidd")

   LVelThreshold = 0.0

   particles = liquid.getParticlesColliding()

   for particle in particles:
      pos = particle.getPosition()
      vel = particle.getVelocity()
      if particle.getVelocity().module() > LVelThreshold:
         liquid2.addParticle(pos, vel)
         liquid.removeParticle(particle.getId())

   for particle in particles:
      pos = particle.getPosition()
      vel = particle.getVelocity()
      if particle.getVelocity().module() > 3:
         foam.addParticle(pos, vel)
         liquid.removeParticle(particle.getId())
         liquid2.removeParticle(particle.getId())

   fparticles =foam.getParticles()
   for fparticle in fparticles:
      fpos = fparticle.getPosition()
      fvel = fparticle.getVelocity()
      fnor =fparticle.getNormal()
      if fparticle.getAge() > (20 + randint(0,20)) and fnor.getY() < 0:
         liquid.addParticle(fpos, fvel)
         liquid2.addParticle(fpos, fvel)
         foam.removeParticle(fparticle.getId())

   fparticles =Liquidc.getParticles()
   for fparticle in fparticles:
      fpos = fparticle.getPosition()
      fvel = fparticle.getVelocity()
      fnor =fparticle.getNormal()
      if fparticle.getAge() > (15 + randint(0,15)) and fnor.getY() < 0:
         liquidd.addParticle(fpos, fvel)
         Liquidc.removeParticle(fparticle.getId())



#--------------------------------------------------
# Function: onSimulationFrame
#--------------------------------------------------

def onSimulationFrame():
 
  emitter = scene.getEmitter("liquidd")
  particle = emitter.getFirstParticle()
  speed_threshold = 0.0
  factor_posX = 0.00
  factor_posY = 0.01
 
  while particle:
 
    velocity = particle.getVelocity()
    velocityY = velocity.getY()
    position = particle.getPosition()
    positionX = position.getX()
    positionY = position.getY()
    positionZ  = position.getZ()
 
    if (velocityY > speed_threshold) :
      new_positionX = positionX - factor_posX
      new_positionZ  = positionZ + factor_posY
      new_position = Vector.new(new_positionX, positionY , new_positionZ)
      particle.setPosition(new_position)
 
    particle = particle.getNextParticle()


User avatar
tsn
Posts: 915
Joined: Fri Oct 27, 2006 10:36 am

Add Foam/bubbles per Object

Postby tsn » Tue Oct 09, 2007 10:14 am

Great! I´m really curious about your simulation and am looking forward to it. Hope you´ll share some images.

...and thanks for sharing your script.

shaun_michael
Posts: 4766
Joined: Sun Sep 10, 2006 8:04 am

Add Foam/bubbles per Object

Postby shaun_michael » Tue Oct 09, 2007 4:04 pm

Nice one Kris. I'll have a read through when I get a spare mo.

Shaun

User avatar
FA1LURE
Posts: 224
Joined: Sat Feb 02, 2008 1:11 pm

Add Foam/bubbles per Object

Postby FA1LURE » Fri Aug 07, 2009 7:06 am

Sounds like most of yous have been successful on this venture after the script got posted.

Me on the other hard is having difficulty making it work.

The script is giving me no errors, but what im trying to accomplish with this script is foam you would get from washing your hands, or like using a middles school bubble blower persae.

Any suggestions.

Thanks.
Defeat enemies with success.

funstance
Posts: 6
Joined: Wed Oct 15, 2008 12:14 pm

Add Foam/bubbles per Object

Postby funstance » Mon Dec 26, 2011 2:45 pm

"After all, champagne is only chanpagne (apart from the region of France it comes from)"

Sorry buddy boy but it ain't from France as we were told. :happy:

(currently working on some champagne sim so came across this knowledge thread.

As its clearly documented that Christopher Merret (an Englishman) documented the process a good 30 odd years before Don Perignon.
And bell didn't invent the telephone either just stole the patent and tempered with it,
same way I'm going to temper with this script ... ;)


Return to “Python-Scripting”

Who is online

Users browsing this forum: No registered users and 2 guests