script help

Discussions about the use of Realflow 2012
jumax
Posts: 30
Joined: Mon Jul 20, 2009 11:35 am

script help

Postby jumax » Tue Apr 29, 2014 2:01 pm

Hi

I need to make a simple adjustment to a script, but I am quite new to it so i am having difficulty. basically I need to check the collision on more than Sphere01 , I also need sphere02 and sphere03. I tried adding them after sphere one as

if ( object == Sphere01, Sphere02 ):

but that seems to break the script and the particles enter the container as soon as they are emitted.


Code: Select all

def onSimulationStep():
      particle = Circle01.getFirstParticle()
      while (particle):
            object = particle.getCollidingObject()
            if ( object == Sphere01 ):
                  Container01.addParticle(particle.getPosition(),particle.getVelocity())
                  Circle01.removeParticle(particle.getId())
            particle = particle.getNextParticle()



Thanks


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

Re: script help

Postby tsn » Tue Apr 29, 2014 6:36 pm

Here you are ;)

Attach this script to the "FramesPre" branch of the Simulation Events tree (right-click on "FramesPre" and choose "Add script"). Then you'll get a new editor where you can copy/paste the code to. I wouldn't use that old-fashioned and obsolete "Master" script template anymore - it's just there for RF4 compatibility. Of course, you can add it to "StepsPre" as well. This depends on the desired level of accuracy and how much time you have. In most cases, a per-frame execution gives satisfying results.

Code: Select all

collisionObjects = ["Sphere01","Sphere02","Sphere03"]

source = scene.get_PB_Emitter("Circle01")
target = scene.get_PB_Emitter("Container01")

particleList = Circle01.getParticles()
for particle in particleList:
   collObject = particle.getCollidingObject()
   if (collObject != None):
     if (collObject.getName() in collisionObjects):
         source.removeParticle(particle.getId())
        target.addParticle(particle.getPosition(),particle.getVelocity())


Cheers,
Thomas

jumax
Posts: 30
Joined: Mon Jul 20, 2009 11:35 am

Re: script help

Postby jumax » Wed Apr 30, 2014 9:52 am

Thank you! I will give it a go right now.


Return to “Realflow 2012”

Who is online

Users browsing this forum: No registered users and 1 guest