Re-use particle effects?

Hi all,
I am trying to re-use a particle effect like this:

t = Sequence(Func(mbp.start,render),Func(mbp.show),delay,Func(mbp.hide),Func(mbp.__init__),)

mbp is an instance of the particle effect class, see the code below.
I start the effect then show it, delay so it can be seen, then hide it.
Then run the init to reset the effect back to it’s starting state.

Else where in the code when i need to display and reuse the effect, this is what i do.

t.start

Just start the sequence.
The question is, should i use init to restore the starting state of the effect. Reset did not work. Nor did anything else i tried.

The effect is wrapped in a class from an example i found on the forum.
Here is the first part of the class.


class BalloonPop(ParticleEffect):
  def __init__(self):
    ParticleEffect.__init__(self)
    
    #bp = ParticleEffect() 
    self.reset()
    self.setPos(0.000, 0.000, 0.000)
    self.setHpr(0.000, 0.000, 0.000)
    self.setScale(1.000, 1.000, 1.000)
    p0 = Particles('pop')
    # Particles parameters
    p0.setFactory("PointParticleFactory")
    p0.setRenderer("SparkleParticleRenderer")
    p0.setEmitter("SphereSurfaceEmitter")
    # max number on screen at once

Is there a best method for re-using effects?

Thanks
:slight_smile:

I think it’s best to re-create the ParticleEffect if possible. Explicitly calling init on an already-created ParticleEffect can result in a memory leak.

It is unfortunate that playing a ParticleEffect in an interval ends up destroying the effect, but that’s the way that it is right now.

David

i had a way to reuse particles effects but i hated the particle effects so much i think through it a way. Use my own particle/projectile system now.

Hi Treeform,

Is your own particule effet system available in your code of IronAngel?

no that is LegionsDD particle system. I was hoping to rewrite my particle system in c++ here soon. But i have GUI list box to finish first.
this is the only thing i have online affuniverse.com/artdepot/Treeform/exp.zip
i will try go get some thing decent out soon.

Thanks for the help.

Question: using particles in a class like the code snip above; can you get to and set the birthrate and other vars. I am hoping that would allow the effect to be restored to the original starting state.

i guess, in the script above there is no birth rate you just create particle when ever you want. If you want to create 100 particles right now you can do so. The main feature i was trying to do is “particle creates a trail” I just add one smoke particle as it moves. Explosions normally work that way too.

Ok, i think i have a fix for this.

Here is the particle class code


class BalloonPop(ParticleEffect):
  
  def __init__(self):
    ParticleEffect.__init__(self)
    #bp = ParticleEffect() 
    self.reset()
    self.setPos(0.000, 0.000, 0.000)
    self.setHpr(0.000, 0.000, 0.000)
    self.setScale(1.000, 1.000, 1.000)
    p0 = Particles('pop')
    # Particles parameters
    p0.setFactory("PointParticleFactory")
    p0.setRenderer("SparkleParticleRenderer")
    p0.setEmitter("SphereSurfaceEmitter")
    # max number on screen at once
    p0.setPoolSize(100)
    # time between birth
    p0.setBirthRate(0.100)
    p0.setSoftBirthRate(50)
    # how may at one birth
    p0.setLitterSize(5)
    p0.setLitterSpread(0)
    # how long it will run
    p0.setSystemLifespan(0)
    p0.setLocalVelocityFlag(1)
    p0.setSystemGrowsOlderFlag(0)
    # Factory parameters
    p0.factory.setLifespanBase(0.1000)
    p0.factory.setLifespanSpread(0.0000)
    p0.factory.setMassBase(1.0000)
    p0.factory.setMassSpread(0.0000)
    p0.factory.setTerminalVelocityBase(400.0000)
    p0.factory.setTerminalVelocitySpread(0.0000)
    # Point factory parameters
    # Renderer parameters
    p0.renderer.setAlphaMode(BaseParticleRenderer.PRALPHANONE)
    p0.renderer.setUserAlpha(1.00)
    # Sparkle parameters rgb 1=max  0=none   0,0,0=black   1,1,1=white   
    p0.renderer.setCenterColor(Vec4(1, 0, 0, 1.00))
    p0.renderer.setEdgeColor(Vec4(1, 1, 1, 1.00))
    p0.renderer.setBirthRadius(0.0700)
    p0.renderer.setDeathRadius(0.1800)
    p0.renderer.setLifeScale(SparkleParticleRenderer.SPSCALE)
    # Emitter parameters
    p0.emitter.setEmissionType(BaseParticleEmitter.ETRADIATE)
    p0.emitter.setAmplitude(1.0000)
    p0.emitter.setAmplitudeSpread(0.0000)
    p0.emitter.setOffsetForce(Vec3(0.0000, 0.0000, 0.0000))
    p0.emitter.setExplicitLaunchVector(Vec3(1.0000, 0.0000, 0.0000))
    p0.emitter.setRadiateOrigin(Point3(0.0000, 0.0000, 0.0000))
    # Sphere Surface parameters
    p0.emitter.setRadius(.5000)
    self.addParticles(p0)

Here is the sequence i setup to control the particle effect.

mbp = BalloonPop()
t = Sequence(Func(mbp.start, render),Wait(1),Func(mbp.disable))

Notice the sequence uses the disable method. It will start, delay 1 second then disable the effect.
To activate the effect is use this.

mbp.setPos(5,0,0)
t.start()

Just set a new position then call the sequence start method. I watched memory use while i called the code several times with no change in memory.

I tried using softstart and softstop but could not get it to work.
Has anybody used the clearToInitial() method of particleEffect?
It sounds like what i want, but could not see it’s effect.
Any comments would be welcome on how to re-use effects with out causing memory problems.

i think it messes up when you run on windows … i don’t remember but i think i solved it by reseting the internal particle timer also but it still was super slow.