Particle effect error

Hi quick question, why does this error keep popping up when I try to do particle effects?

Known pipe types:
  CocoaGraphicsPipe
(all display modules loaded.)
2019-12-07 22:29:13.001 Python[9097:229512] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to (null)
:ParticleEffect(warning): loadConfig: failed to load particle file: '/Users/38167/PycharmProjects/viren/venv/wood.jpg'
Traceback (most recent call last):
  File "/Users/38167/PycharmProjects/viren/scene.py", line 155, in <module>
    app = MyApp()
  File "/Users/38167/PycharmProjects/viren/scene.py", line 18, in __init__
    p.loadConfig("/Users/38167/PycharmProjects/viren/venv/wood.jpg")
  File "/Users/38167/PycharmProjects/viren/venv/lib/python3.7/site-packages/direct/particles/ParticleEffect.py", line 206, in loadConfig
    exec(data)
ValueError: source code string cannot contain null bytes

here is a snippet of my code, I might be doing something wrong

from direct.particles.ParticleEffect import ParticleEffect

class MyApp(ShowBase):

    def __init__(self):
        ShowBase.__init__(self)
        base.enableParticles()
        p = ParticleEffect()
        p.loadConfig("/Users/38167/PycharmProjects/viren/venv/wood.jpg")
        p.start(parent=self.render, renderParent=self.render)

Thanks!

Ah. You seem to be attempting to load an image as a particle effect. What “loadConfig” expects is instead a particle-definition file, such as saved from the Particle Panel sample-application.

So then how do I get a particle-definition file? So confused on what that is.

Thanks!

As I said: it’s made via the Particle Panel sample-application. The Particle Panel (with a few bugs and rough patches, granted) allows you to design a particle effect, then save a particle-definition file (with the file-extension “ptf”, if I recall correctly). You can then load this file via “loadConfig”.

(You can also just construct your particle effect via code–but that’s a much longer, more tedious, and less intuitive way of doing things.)

[edit] I think that there are also some alternatives to the particle panel to be found if you search the forum.

I’m on macos how do I make it? I heard it’s only for Windows or something.

https://www.panda3d.org/manual/?title=Particle_Effects

Yeah the particle panel is for Windows, I literally just said. I’m on a mac

Take a look at the “samples” folder and examine the contents of the “particles” folder. I did not know that the panel is available for Windows, I used to think that a multi-platform thing.

I’ve used the Particle Panel under Ubuntu Linux, I believe, so it’s very much not a Windows-only thing.

The only mention of Windows that I see on manual page for the Particle Panel is a line that gives its location under Windows–nothing that indicates that it only functions under Windows, as far as I see.

So then how do I use it on macos? I have no experience.

The same way as you use it on other systems: run it as a Python program.

If MacOS doesn’t allow you to just run it that way, open a terminal/console/whatever-Mac-might-call-it at the location of the Particle Panel, and run “python particle_panel.py”.

(I don’t know about Mac, but under Ubuntu Linux I’ve been able to easily open a terminal at a given folder by opening the folder as per usual in the OS’s file-manager, then right-clicking on empty space within the folder and selecting “Open in terminal”. Mac might have a similar feature.

If not, just open a terminal and navigate via terminal commands to the location.

Of course, this is all to be done only if Mac doesn’t let you just run the program directly from the file-manager, perhaps by double-clicking it, or by right-clicking it and selecting “run”.)

So like cd . But that’s the thing, what’s the file path to get to it?

I don’t use Mac, I’m afraid, so I don’t know where Panda gets installed on that platform. :/

The basic idea would be to locate the Panda installation. In that, you should find a folder named “samples”, and in that you should find one named “particles”. The Particle Panel should be there, as a Python file named “particle_panel.py”.

I think I found it , is it particle_panel.py?

That should be it, yes. :slight_smile:

ok I have it open now what do I do after I have the desired particle effect?

Save it! Go to the “File” menu, select “Save params”, and save your new particle-definition file. Then copy that file (and any images that might be associated with it, such as particle-sprites) into the relevant directory/directories of your program. Finally, load the particle definition file in your program via “loadConfig”.

I don’t have Save params option?

So, I think it will be what you desired:

self.reset()
self.setPos(0.000, 0.000, 0.000)
self.setHpr(0.000, 0.000, 0.000)
self.setScale(2.000, 2.000, 2.000)
p0 = Particles.Particles('particles-1')
# Particles parameters
p0.setFactory("PointParticleFactory")
p0.setRenderer("PointParticleRenderer")
p0.setEmitter("DiscEmitter")
p0.setPoolSize(10000)
p0.setBirthRate(0.0200)
p0.setLitterSize(300)
p0.setLitterSpread(100)
p0.setSystemLifespan(0.0000)
p0.setLocalVelocityFlag(1)
p0.setSystemGrowsOlderFlag(0)
# Factory parameters
p0.factory.setLifespanBase(0.5000)
p0.factory.setLifespanSpread(0.2500)
p0.factory.setMassBase(2.0000)
p0.factory.setMassSpread(0.0100)
p0.factory.setTerminalVelocityBase(400.0000)
p0.factory.setTerminalVelocitySpread(0.0000)
# Point factory parameters
# Renderer parameters
p0.renderer.setAlphaMode(BaseParticleRenderer.PRALPHAOUT)
p0.renderer.setUserAlpha(0.45)
# Point parameters
p0.renderer.setPointSize(3.00)
p0.renderer.setStartColor(LVector4(0.25, 0.90, 1.00, 1.00))
p0.renderer.setEndColor(LVector4(1.00, 1.00, 1.00, 1.00))
p0.renderer.setBlendType(PointParticleRenderer.PPONECOLOR)
p0.renderer.setBlendMethod(BaseParticleRenderer.PPNOBLEND)
# Emitter parameters
p0.emitter.setEmissionType(BaseParticleEmitter.ETCUSTOM)
p0.emitter.setAmplitude(1.0000)
p0.emitter.setAmplitudeSpread(0.0000)
p0.emitter.setOffsetForce(LVector3(0.0000, 0.0000, 4.0000))
p0.emitter.setExplicitLaunchVector(LVector3(1.0000, 0.0000, 0.0000))
p0.emitter.setRadiateOrigin(LPoint3(0.0000, 0.0000, 0.0000))
# Disc parameters
p0.emitter.setRadius(0.0500)
p0.emitter.setOuterAngle(356.1859)
p0.emitter.setInnerAngle(0.0000)
p0.emitter.setOuterMagnitude(2.0000)
p0.emitter.setInnerMagnitude(1.0000)
p0.emitter.setCubicLerping(0)
self.addParticles(p0)
f0 = ForceGroup.ForceGroup('gravity')
# Force parameters
force0 = LinearVectorForce(LVector3(0.0000, 0.0000, -1.0000), 25.0000, 1)
force0.setActive(1)
f0.addForce(force0)
force1 = LinearJitterForce(3.0000, 1)
force1.setActive(1)
f0.addForce(force1)
self.addForceGroup(f0)

Save it to a file and download.

p = ParticleEffect()
p.loadConfig("file")

that’s basicallly what I’m doing right now.