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))