release #3: istrolid.com/p/panda3d/pyro/pyro3.zip
Pyro is a particle/projectile system. Basically its a mixed C++/Python library used to create dynamic effects such as projectiles, trails, particles, radar and even line drawing. At its core pyro is NodePath with various draw commands. Its has some optimizations and genially runs faster then other methods that procedurally generate geometry.
One other core concept is the plate. Plate is an image composed of many different frames look at the 2 plates provided in the /data section. The idea of plate comes from necessity of sending only one geometric object per Pyro particle system. The included tool createplate.py that help plate creation is included.
The radar_test.py has the complete example of how to use this low level component.
# simply create
generator = Pyro("Generator")
generator.reparentTo(render)
# in your loop or any place else
generator.begin(base.cam,render)
...
generator.tri( v1, c1, uv1, v2, c2, uv2, v3, c3, uv3);
generator.particle(pos, frame, size, color, rotation);
generator.billboard(pos, frame, size, color);
generator.segment(start, stop, frame, size, color);
generator.explosion(pos, frame, size, color, seed, number, distance);
generator.stream( start, stop, frame, size, color, number, offset);
...
generator.end()
There is are some commands and many more will be added.
But there is a higher level python library written on top of this interface that allows much better particle management. Each particle is a full python class with specific methods and attributes. It is beneficial to look at the explosions.py to see all the many different ways particle can be scripted creating many many effect. One pyro particle roughly corresponds to a c++ call on the Pyro generator class so with a particle of type “explosion” one can draw 100’s of particle in that spherical propagate form one center point.
The pyro_test.py has the example of using this higher level system.
tg = Pyro(loader.loadTexture("data/plate2.png"),16,pyro_animations,10000)
The pyro_animations is the dictionary of particle animation name to start, number of frames, and end tuple. It can be coded by hand but its much easier to generate it with createplate.py. pyro_animations look some thing like this
pyro_animations = {
'beam-blue-A-': (238, 3, 241),
'beam-red-A-': (241, 3, 244),
'bigsploA': (128, 8, 136),
'bigsploB': (136, 8, 144)}
The particle definition has many components:
class SmallExplosion(Particle):
duration = 10.
type = "particle"
def restart(self,center,size=.5):
self.pos = Vec3(center)
self.size = size
self.animate(choice(["explo1-","explo2-","explo3-","explo4-"]))
self.rotation = random()*360
def do(self,dt):
""" alter the particle """
self.size += (self.time*dt)**2*.2
self.spread = 2*(self.time/self.duration*10)**.5
self.frame = self.startFrame + (self.numFrames)*self.time/self.duration
The restart is the init of the particle. ParticleManager caches all the created particle instances so that less object allocations will be needed, but it just have to restart used particles. To create a new particle one just has to call new on your particle manager.
tg.new(Chunk,Vec3(0,0,0))
I will be adding more functionality such as use of the excising particle emitters, use of nerb’s curves for motion trails, better documentation and an all around easier way to use it.