Reset particle velocity in XYZ

Discussion about scripting with Python
bmecohen
Posts: 28
Joined: Thu Sep 27, 2012 12:55 pm

Reset particle velocity in XYZ

Postby bmecohen » Fri Nov 30, 2012 10:01 pm

Hello!

I was wondering, how should I do a scene where the initial state has no particle velocities. Like if I made a clean surface, I would like to see min to max 0.0 values in particle velocity statistics not the freeze transformation way.

I tried to write a code, but somehow, this is not working. Maybe the velocity could not be reset this way, just like getX()...
If You know any other way, it would be also great.

Code: Select all

def onSimulationStep():

   threshold = 0.0
   emitter = scene.getEmitter("Circle01")
   particle = emitter.getFirstParticle()
   while (particle) :
            vel = particle.getVelocity()
            vel_mag = vel.module()
            if ( vel_mag > threshold):
               vel == 0.0
            particle = emitter.getNextParticle()


Have a great day!


User avatar
Otuama
Posts: 1155
Joined: Fri Apr 02, 2010 12:56 am
Location: Swansea
Contact:

Re: Reset particle velocity in XYZ

Postby Otuama » Sat Dec 01, 2012 11:53 am

All you really need to do is this:

Code: Select all

emitter = scene.getEmitter("Circle01")
particle = emitter.getFirstParticle()
while (particle) :

   #Get the velocity
   #This variable can be used if you DON'T want a
   #direction to be given a 0.0 velocity
   vel = particle.getVelocity().module()

   #Set the velocity to 0.0
   #You only need to use 'vel' if you want the
   #particles to have a correct velocity.  for
   #example, I've given X the correct velocity
   particle.setVelocity(Vector.new(vel,0.0,0.0))

   #It needs to be this, not
   #particle = emitter.getNextParticle()
   particle = particle.getNextParticle()


You may need to use the code each substep.
iCreate Ltd
'Strength does not come from physical capacity. It comes from an indomitable will.' - Gandhi
'What Does Success Look Like?' - iCreate Ltd


Return to “Python-Scripting”

Who is online

Users browsing this forum: No registered users and 4 guests