Panda3D Manual: Using the Particle Panel
<<prev | top | next>> |
The particle panel must be used from the python command prompt. Open a command prompt and enter the folder you wish to run this in.
python import direct.directbase.DirectStart from direct.tkpanels import ParticlePanel pp = ParticlePanel.ParticlePanel() run()
Once the desired effect is achieved, save the file out. This, after some alterations, may be inserted into your current project code. First, copy and paste the code into your existing project code. Above the first line, add this line:
from direct.particles.ParticleEffect import ParticleEffect from direct.particles.Particles import Particles from pandac.PandaModules import * from direct.interval.MetaInterval import Sequence from direct.interval.FunctionInterval import Func from direct.particles.ParticleEffect import ParticleEffect f = ParticleEffect()
After that, replace any “self” variable with the variable “f.” Finally, add these lines to the end of your particle effect code:
t = Sequence(Func(f.start, render, render),) t.start()
Also, to use any particle effects, they must be enabled through a base command.
base.enableParticles()
Another way to use the particle effect generated by the particle panel is to wrap it in a custom ParticleEffect class. This will allow you to easily create and manage multiple effects.
from direct.particles.ParticleEffect import ParticleEffect from direct.particles.Particles import Particles from pandac.PandaModules import * from direct.interval.MetaInterval import Sequence from direct.interval.FunctionInterval import Func from direct.particles.ParticleEffect import ParticleEffect class MyParticleEffect(ParticleEffect): def __init__(self): ParticleEffect.__init__(self) **INSERT GENERATED CODE HERE**
Like this, you don't have to replace all occurances of "self", and you can call all ParticleEffect methods directly on the class you just made. To render the particle effect, do the following:
effect = MyParticleEffect() effect.start(render) effect.setPos(0, 0, 10)
After you use it you should remove it like this:
effect.cleanup() effect.removeNode()
Calling cleanup() is very important, you will end up with a memory leak when it is not called.
<<prev | top | next>> |