[SOLVED] ParticleMonkey on the GUI node?

I’m playing with ParticleMonkey

in particular I want to attach a particle effect to the GUI node (rather than the root node). Unfortunately it don’t work:

public class HelloJME3_2 extends SimpleApplication {

    public static void main(String[] args) {
        HelloJME3_2 app = new HelloJME3_2();
        app.setShowSettings(false);
        AppSettings settings = new AppSettings(true);
        app.setSettings(settings);
        app.start(); // start the game
    }

    @Override
    public void simpleInitApp() {

        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
        mat.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off);
        Texture tex = assetManager.loadTexture("Effects/Particles/part_light.png");
        mat.setTexture("Texture", tex);

        Emitter emitter = new Emitter("test", mat, 100);
        emitter.setStartSpeed(new ValueType(6.5f));
        emitter.setLifeFixedDuration(2.0f);
        emitter.setEmissionsPerSecond(20);
        emitter.setParticlesPerEmission(1);
        emitter.setShape(new EmitterCone());
        ((EmitterCone)emitter.getShape()).setRadius(0.005f);

        emitter.setLocalTranslation(0, 0.5f, 0);
        guiNode.attachChild(emitter);
    }
}

Despite tweaking the translation values, I never see the effect.

It’s positioned at pixel 0,0? (effectively)

Keep in mind that the scale of screen space is HUGE compared to a normal scene. In the GUI 1 unit = 1 pixel. In a regular scene 1 unit = a meter (usually).

Edit: maybe position is somewhere like 100, 100 and scale it by 100 to see if you see it. At a glance, the parameters seem to say that particles will only travel 12 pixels before dying.

1 Like

I see “something” with

emitter.setStartSize(new ValueType(3));

And by “something” I mean the corners of huge particles on the border of the screen.

public class HelloJME3_2 extends SimpleApplication {

    public static void main(String[] args) {
        HelloJME3_2 app = new HelloJME3_2();
        app.setShowSettings(false);
        AppSettings settings = new AppSettings(true);
        app.setSettings(settings);
        app.start(); // start the game
    }

    @Override
    public void simpleInitApp() {

        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
        mat.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off);
        Texture tex = assetManager.loadTexture("Effects/Particles/part_light.png");
        mat.setTexture("Texture", tex);

        Emitter emitter = new Emitter("test", mat, 100);
        //emitter.setStartSpeed(new ValueType(6.5f));
        emitter.setLifeFixedDuration(2.0f);
        emitter.setEmissionsPerSecond(20);
        emitter.setParticlesPerEmission(1);
        emitter.setShape(new EmitterCone());
        emitter.setStartSize(new ValueType(3));
        ((EmitterCone)emitter.getShape()).setRadius(0.005f);

        emitter.setLocalTranslation(0, 0.5f, 0);
        guiNode.attachChild(emitter);
    }
}

The effect don’t seem to respond to values. it’s as if everything was internally mutiplied by 100… maybe I’m missing something?

You may want to post a screen shot. “Huge” can mean differing things. “On the border of the screen” could mean a few things.

…after all, you are positioning the emitter at the corner of the screen so one interpretation of “on the border” would be expected behavior.

I would expect the particle to spawn (and therefore be centered) on the bottom left corner. Instead is floating mostly (about 90%) offscreen

Mmm… something in my memory is tickling about assumptions in Particle.j3md. It tends to mess up in anything but regular scale=1and may mess up in the GUI node.

…something about the sprite size calculation and the quadratic parameter. I ever fully bothered to understand what this math is doing… but I suspect it totally messes up in ortho mode.

Particles have to have the translucent bucket filter added to post processors.

I don’t think that’s true unless you put the particles in the translucent bucket.

There is certainly nothing about the material that requires that.

Hmm, well this is a new one for me. I haven’t tried running the particle system in the gui node.

So, the emitter does default to translucent but you should be able to drop it into another bucket after construction or just add the translucent filter (although the filter doesn’t appear to like the gui bucket).

That being said, I played around with this a little bit and was able to get the particles to partially show up but I think most of them are getting culled. The cone emitter for example is shooting particles out in 3d space. Also, I had to reduce the scale of the particles by a lot since they were still too big for the gui bucket and change the emitter type. I would have to play around with it a little bit since I haven’t tried to use the particle system in the gui node before. I suspect you would need some sort of change to the emitters to help support a 2D workflow.

I’ll play around with it a bit more and see if I can work it out.

1 Like

angry-face

That seems a really odd choice. Transparent bucket I could see… but Translucent hardly makes sense as a default.

Note that it’s especially relevant in the case of the guiNode since the only thing special about the guiNode is that it’s in the Gui bucket. So anything you put in it that already sets its own bucket won’t render correctly.

So it seems that if you want to put particles in the guiNode you first have to make sure to clear their bucket or force it to the GuiBucket or none of the positioning will make sense.

Then you have to deal with the odd quadratic distance sizing equation in the shader.

Not sure culling matters or not as those other things could confuse culling already.

It’s honestly been so long, i’m not sure if that was even my code or not. I’ve only ever used the particle system with the translucent filter because of the soft particles so it’s never stuck out to me.

Sorry… I already assumed it was from JME code.

…like when BitmapText used to force itself into the gui bucket for no good reason.

Solved by using a Particle2D.j3md that I somehow included into my project and used… some time ago.

Is that inside of jME or something you picked up?

Is part of my library. But have no memory on how I made this…

Maybe borrowed from @t0neg0d?

Seems like the only difference is that it ignore the quadratic parameter. Sounds familiar.