[SOLVED] Accessing ParticleEmitter in Scene Composer

Hi all. Is there a way to access the ParticleEmitter in SceneComposer through java code? I wanted to make a CustomControl that changes the color of the ParticleEmitter. Just need to know how to get the ParticleEmiiter from SceneComposer through code. Thanks 8)

K Out!

Its a normal spatial, so rootNode.getChild(name);

1 Like

:facepalm: I’m such a dummy. Thanks Normen =D , I forgot I could take it from the rootNode :lol:

Here is the code for it if anyone else happens to come across this problem :smiley:

[java]
ParticleEmitter particle = (ParticleEmitter)((Node) spatial).getChild(“Emitter”);
[/java]

Sorry for bring back old topics but when I use node.getChild(0);
It pop up a error about the jme3.scene.Node cannot cast to jme3.effect.ParticleEmitter.
Here is my code:

[java]
explo =
assetManager.loadModel(“Scenes/Explosion.j3o”);
Node node = new Node(“ParticleNode”);
node.attachChild(explo);
rootNode.attachChild(node);

effect = (ParticleEmitter) node.getChild(0);
effect.emitAllParticles();
[/java]

I want to let the particle in Explosion.j3o to emit all of the time. Does this is a bug or the code had some error ? Thanks everyone !

This means that the root of the Explosion.j3o file is a node, not a particle emitter. You’ll need to find out where the particle emitter is actually attached in the contents of the j3o.

Ya, thanks you. :grinning: I fix the code and it is working !
Here is my code after fix:

ParticleEmitter shockwave = (ParticleEmitter) 
node.getChild("shockwave");
1 Like

Please note, you dont need to know it(child name/etc) each time.

If you dont need select exact thing from scene graph, you can select first one or just every.
like:

    SceneGraphVisitor visitor = new SceneGraphVisitor() {
      @Override
      public void visit(Spatial spatial) {
          if(spatial instanceof ParticleEmitter){
            // it is particle emitter. use (ParticleEmitter)spatial
          } else if(spatial instanceof Node){
            // it is Node. use (Node)spatial
          } else if(spatial instanceof Geometry){
            // it is Geometry. use (Geometry)spatial. example ((Geometry)spatial).getMesh()
          }
      }
    };
    yourModelSpatial.breadthFirstTraversal(visitor);
1 Like