Kill isolated post process script

Share your scripts with other members
lukeiamyourfather
Posts: 2880
Joined: Mon Oct 15, 2007 4:09 pm
Contact:

Kill isolated post process script

Postby lukeiamyourfather » Wed Oct 22, 2008 9:43 pm

This script removes particles as a post process, like what the kill isolated daemon does during a simulation except with more control. Its not posted on the NL site yet, wanted to get input and tests from other users before doing so. Cheers!

Code: Select all

"""
killIsolatedPostProcess.rfs

Load particles into a blank scene with a binary loader, then run the script. It will probably take a few iterations to get something useful, so be patient. The parameters are explained below.

Age threshold - selects particles based on age, only particles older than the threshold will be processed
Distance threshold - distance to look for neighbor particles (smaller is faster but can be less accurate)
Particle threshold - how many neighbors a particle must have to survive (dependent upon the distance threshold)
First frame - by default is the current frame, set as desired
Last frame - by default is the current frame, set as desired

The default values can be easily changed in the script to suit whatever scale and resolution is needed. To speed the process, open multiple instances of RealFlow and use different frame ranges for each instance. Enjoy!

Luke Olson
luke.s.olson@gmail.com
2008-10-22
"""

#GUI setup and parameters
form = GUIFormDialog.new()

form.addFloatField("Age threshold", 1.0)
form.addFloatField("Distance threshold", 0.5)
form.addIntField("Particle threshold", 10)
form.addIntField("First frame", scene.getCurrentFrame())
form.addIntField("Last frame", scene.getCurrentFrame())

if form.show() == GUI_DIALOG_ACCEPTED:
   
   emitter = scene.getEmitter("Binary_Loader01")
   
   ageThreshold = form.getFieldValue("Age threshold")
   distanceThreshold = form.getFieldValue("Distance threshold")
   particleThreshold = form.getFieldValue("Particle threshold")
   firstFrame = form.getFieldValue("First frame")
   lastFrame = form.getFieldValue("Last frame")
   
   #Inform user of values used, good for looking back on and revising parameters
   scene.message("Parameters for particle removal: n n -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- n n Age threshold: %s n Distance threshold: %s n Particle threshold: %s n First frame: %s n Last frame: %s n n -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- n n" % (ageThreshold, distanceThreshold, particleThreshold, firstFrame, lastFrame))
   
   for frame in range(firstFrame, lastFrame +1):
      particlesRemoved = long(0)
      exemptByAge = long(0)
      scene.setCurrentFrame(frame)
      beginParticleCount = len(emitter.getParticles())
      scene.message("Begin particle filtering with %s particles on frame %s" % (beginParticleCount, frame))
      particle = emitter.getFirstParticle()
      #Look at the particle age. ignore and move on if particle is not old enough (grealy improves performance when used properly)
      while particle:
         if particle.getAge() > ageThreshold:
            if len(particle.getNeighbors(distanceThreshold)) < particleThreshold:
               #Remove the particle if all conditions are met
               emitter.removeParticle(particle.getId())
               particlesRemoved = particlesRemoved + 1
               particle = particle.getNextParticle()
            else:
               particle = particle.getNextParticle()
         else:
            exemptByAge = exemptByAge + 1
            particle = particle.getNextParticle()
      #Inform user what has occured, how many particles were excempt from age and how many were removed
      scene.message("Removed %s particles from frame %s, ignored %s particles by age" % (particlesRemoved, frame, exemptByAge))
      emitter.export()
      endParticleCount = beginParticleCount - particlesRemoved
      scene.message("Exported %s particles for frame %s" % (endParticleCount, frame))


lukeiamyourfather
Posts: 2880
Joined: Mon Oct 15, 2007 4:09 pm
Contact:

Kill isolated post process script

Postby lukeiamyourfather » Wed Oct 22, 2008 10:56 pm

Some slight changes to the messages and a change to how the particles are removed. Instead of removing them as the script goes, it finds all of the particles to be removed on a single frame and then removes all of them at once. This prevents a sort of decay where particles would be removed since their neighbors were deleted earlier in the script. Cheers!

Code: Select all

"""
killIsolatedPostProcess.rfs

Load particles into a blank scene with a binary loader, then run the script. It will probably take a few iterations to get something useful, so be patient. The parameters are explained below.

Age threshold - selects particles based on age, only particles older than the threshold will be processed
Distance threshold - distance to look for neighbor particles (smaller is faster but can be less accurate)
Particle threshold - how many neighbors a particle must have to survive (dependent upon the distance threshold)
First frame - by default is the current frame, set as desired
Last frame - by default is the current frame, set as desired

The default values can be easily changed in the script to suit whatever scale and resolution is needed. To speed the process, open multiple instances of RealFlow and use different frame ranges for each instance. Enjoy!

Luke Olson
luke.s.olson@gmail.com
2008-10-22
"""

#GUI setup and parameters
form = GUIFormDialog.new()

form.addFloatField("Age threshold", 1.0)
form.addFloatField("Distance threshold", 0.5)
form.addIntField("Particle threshold", 10)
form.addIntField("First frame", scene.getCurrentFrame())
form.addIntField("Last frame", scene.getCurrentFrame())

if form.show() == GUI_DIALOG_ACCEPTED:
   
   emitter = scene.getEmitter("Binary_Loader01")
   
   ageThreshold = form.getFieldValue("Age threshold")
   distanceThreshold = form.getFieldValue("Distance threshold")
   particleThreshold = form.getFieldValue("Particle threshold")
   firstFrame = form.getFieldValue("First frame")
   lastFrame = form.getFieldValue("Last frame")
   
   bucketList = []
   
   for frame in range(firstFrame, lastFrame +1):
      particlesRemoved = long(0)
      exemptByAge = long(0)
      scene.setCurrentFrame(frame)
      del bucketList[:]
      beginParticleCount = len(emitter.getParticles())
      scene.message("Begin particle filtering with %s particles on frame %s" % (beginParticleCount, frame))
      particle = emitter.getFirstParticle()
      #Look at the particle age. ignore and move on if particle is not old enough (grealy improves performance when used properly)
      while particle:
         if particle.getAge() > ageThreshold:
            if len(particle.getNeighbors(distanceThreshold)) < particleThreshold:
               #Add particle to the list of particles to be removed
               bucketList.append(particle.getId())
               particlesRemoved = particlesRemoved + 1
               particle = particle.getNextParticle()
            else:
               particle = particle.getNextParticle()
         else:
            exemptByAge = exemptByAge + 1
            particle = particle.getNextParticle()
      
      #Remove particles that are tagged for removal
      for particle in bucketList:
         emitter.removeParticle(particle)
      #Inform user what has occured, how many particles were excempt from age and how many were removed
      scene.message("Removed %s particles from frame %s, ignored %s particles by age" % (particlesRemoved, frame, exemptByAge))
      emitter.export()
      endParticleCount = beginParticleCount - particlesRemoved
      scene.message("Exported %s particles for frame %s" % (endParticleCount, frame))
      
      #Inform user of values used, good for looking back on and revising parameters
   scene.message("Parameters for particle removal: n n -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- n n Age threshold: %s n Distance threshold: %s n Particle threshold: %s n First frame: %s n Last frame: %s n n -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- n n" % (ageThreshold, distanceThreshold, particleThreshold, firstFrame, lastFrame))

User avatar
tmdag
Posts: 1023
Joined: Thu Jun 28, 2007 2:22 pm
Location: New Zealand
Contact:

Kill isolated post process script

Postby tmdag » Thu Oct 23, 2008 9:11 am

thx luke! great script!
"Do not feed the trolls"
Albert 'tmdag' Szostkiewicz
FX Technical Director
Weta Digital

bluehonda
Posts: 118
Joined: Mon Sep 11, 2006 7:27 am

Kill isolated post process script

Postby bluehonda » Tue Jul 27, 2010 12:01 pm

Thanks Luke! very nice script.

tricecold
Posts: 2
Joined: Sun Dec 18, 2011 3:46 pm

Kill isolated post process script

Postby tricecold » Sun Dec 18, 2011 6:29 pm

this is exactly what i needed except i need to do this for grid particles with no velocity or with a defined range. can u help please.

mrpepe4
Posts: 18
Joined: Thu Aug 09, 2012 8:21 am
Contact:

Re: Kill isolated post process script

Postby mrpepe4 » Tue Mar 18, 2014 2:37 pm

i still couldnt find any working script which deletes selected particles (plus doesnt crash),
so since your script works fine you are my personal hero for this week - thanks a lot!
best,
p4


Return to “User Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest