- You are not logged in. | Login
#1 February 7, 2010 8:32 pm
- wietob
- Member


- Registered: February 3, 2010
- Posts: 16
- Reputation : 0
Limit colliding particles for one object
#2 February 8, 2010 10:54 am
- lukeiamyourfather
- Moderator



- Gender:

- From: Texas
- Registered: October 15, 2007
- Posts: 2555
- Reputation : 44

Re: Limit colliding particles for one object
Sure, in the Python event script use an if statement to check what object the fluid is colliding with. Can you share what script you are using for the foam? Cheers!
#3 February 8, 2010 12:31 pm
- wietob
- Member


- Registered: February 3, 2010
- Posts: 16
- Reputation : 0
Re: Limit colliding particles for one object
Hello
I use the script: MediumBeerFoam
Can you post the code for the if statement to check what object the fluid is colliding with? I´m have no experiences with python.
wietob
Code of Medium BeerFoam:
def onSimulationStep():
from random import randint
# VARIABLES
liquid = scene.getEmitter("beer") #set the name of your chosen liquid emitter (liquid type)
foam = scene.getEmitter("foam") #set the name of your chosen foam emitter (liquid type)
liquid2 = scene.getEmitter("beer2") #same parameters as liquid
# liquid -> foam
LVelThreshold =2.8 # controljs the amount of foam particles forming (raising value = decreasing amount)
#foam -> liquid : two conditions to be met
FVelThreshold =1.5 # Min velocity of foam particles. Minimum velocity particle should have to stay as foam particle (Decreasing value = more foam particles staying)
FHeightThreshold = 0.3 # Max height of foam particles (Raising value = more foam particles staying)
# loop through liquid particles, if colliding and over a certain velocity converts them into foam
particles = liquid.getParticlesColliding()
for particle in particles:
pos = particle.getPosition()
vel = particle.getVelocity()
if particle.getVelocity().module() > LVelThreshold:
foam.addParticle(pos, vel)
liquid.removeParticle(particle.getId())
# loop through foam particles, if under a velocity value and height converts them back to liquid
foamies = foam.getParticles()
for foami in foamies:
FPos = foami.getPosition()
FVel = foami.getVelocity()
FHeight = foami.getPosition().getY()
# Note: if your vertical axis isn't the Y-axis. Change the getY to getX, or getZ as appropiate.
if (foami.getVelocity().module() < FVelThreshold) and (FHeight < FHeightThreshold):
liquid2.addParticle(FPos, FVel)
foam.removeParticle(foami.getId())
#4 February 8, 2010 6:47 pm
- lukeiamyourfather
- Moderator



- Gender:

- From: Texas
- Registered: October 15, 2007
- Posts: 2555
- Reputation : 44

Re: Limit colliding particles for one object
Under the variables section add this, to know what object to ignore. Replace bottle with the name of the actual object.
ignoreObject = scene.getObject("bottle")Replace the third to last line of the liquid loop section with this, which will check if its colliding with the bottle or not. Be sure that the indentation stays the same because Python relies on that to know what is part of the loop and what isn't.
if (particle.getVelocity().module() > LVelThreshold) and (particle.getCollidingObject != ignoreObject):
I haven't tested that but it should work. Let me know if it doesn't. Cheers!
Last edited by lukeiamyourfather (February 8, 2010 6:50 pm)
#5 February 8, 2010 9:24 pm
- FA1LURE
- Member



- Gender:

- From: Downtown LA
- Registered: February 2, 2008
- Posts: 147
- Reputation : 3
Re: Limit colliding particles for one object
I encountered a similar issue a year ago and was able to use this snippet of code to make it work.
collobj = particle.getCollidingObject()
collobjname = collobj.getName()
if collobjname != "spout":
# convert the particle to foamThe "spout" is more of a dropper which helps sculpt the fluid rather than just emitting directly into your beer bottle.
Hope that helps.
CAPS FOR RENDER
#6 February 9, 2010 1:24 pm
- wietob
- Member


- Registered: February 3, 2010
- Posts: 16
- Reputation : 0
Re: Limit colliding particles for one object
Hi,
lukeiamyourfather you are right - it works!
You forgot only the brackets(red).
ignoreObject = scene.getObject("bottle")
if (particle.getVelocity().module() > LVelThreshold) and (particle.getCollidingObject() != ignoreObject):
I´m really happy - thanks a lot!!
wietob
#7 February 9, 2010 9:01 pm
- lukeiamyourfather
- Moderator



- Gender:

- From: Texas
- Registered: October 15, 2007
- Posts: 2555
- Reputation : 44

Re: Limit colliding particles for one object
wietob wrote:
Hi,
lukeiamyourfather you are right - it works!
You forgot only the brackets(red).
ignoreObject = scene.getObject("bottle")
if (particle.getVelocity().module() > LVelThreshold) and (particle.getCollidingObject() != ignoreObject):
I´m really happy - thanks a lot!!
wietob
Good call! Sorry I didn't test it out first (didn't have RealFlow installed).





