Particle Spawn at (0,0,0)

Hello,

I got a problem with the ParticleMesh. I try to make a rocket tail - it looks fine but I get ParticleSpawn on (0,0,0) every time I launch a rocket - i really dont know how to explain that.



 // method is called to get a rocket tail

   public static Node spawnFlare() 
   {
      
      ParticleMesh pMesh = ParticleFactory.buildParticles("partikel", 200);
       pMesh.setStartSize(6);
       pMesh.setReleaseRate(200);
       pMesh.setInitialVelocity(0.05f);
       pMesh.setMinimumLifeTime(100);
       pMesh.setMaximumLifeTime(200);

       pMesh.setRenderState(VisualCtrl.getTexture("flare")); // set a TextureState
       pMesh.setRenderState(as1); // set to a simple BlendingState
       pMesh.setRenderState(zstateOFF); // set ZBuffer OFF

      
       pMesh.updateGeometricState(0, true);
       pMesh.forceRespawn();
      
      
       pMesh.updateRenderState();
 

      return pMesh; // return an attach it to  the rocket


   }




Can someone help me please? I really get mad on that problem :(

Hi Schifty

Didn't really understand the problem here, and the example you posted didn't help show it.

Can you post a more complete (preferably single) java class example that direclty shows the problem?

That would be pretty hard because it is a project with about 30 classes.




public class ParticleEmitter
{   
   
   static BlendState as1;
   static ZBufferState zstateOFF;
   
   // init is loaded early
   public static void init() {
      
      
          as1 = Main.display.getRenderer().createBlendState();
          as1.setBlendEnabled(true);
          as1.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
          as1.setDestinationFunction(BlendState.DestinationFunction.One);
          as1.setEnabled(true);
         
          zstateOFF = Main.display.getRenderer().createZBufferState();
          zstateOFF.setEnabled(false);
}

// method is called to get a rocket tail

   public static Node spawnFlare() 
   {
      
      ParticleMesh pMesh = ParticleFactory.buildParticles("partikel", 200);
       pMesh.setStartSize(6);
       pMesh.setReleaseRate(200);
       pMesh.setInitialVelocity(0.05f);
       pMesh.setMinimumLifeTime(100);
       pMesh.setMaximumLifeTime(200);

       pMesh.setRenderState(VisualCtrl.getTexture("flare")); // set a TextureState
       pMesh.setRenderState(as1); // set to a simple BlendingState
       pMesh.setRenderState(zstateOFF); // set ZBuffer OFF

      
       pMesh.updateGeometricState(0, true);
       pMesh.forceRespawn();
      
      
       pMesh.updateRenderState();
 

      return pMesh; // return an attach it to  the rocket


   }

}




The pMesh ist attached to a moving "Rocket"-Node



public Rocket(float spd, float dmg, MovableObject obj)
   {      
      super("bullet"+count, MyObject.bullet, spd, dmg, obj);
      
      Node model = (Node) VisualCtrl.getMD5Node("rocket").clone();
      model.setLocalScale(0.3f);
      model.setModelBound(new OrientedBoundingBox());
      model.updateModelBound();
      model.updateWorldBound();
      this.attachChild(model);
      this.attachChild(ParticleEmitter.spawnFlare());
   }



Really hope I could make that more clearly



This picture should illustrate the problem more clearly. The initial spawn at 0,0,0 disappears after a little time.

Usually when you're dealing with specific components (eg. particles) it's a good idea to try to reproduce the error in a SimpleGame test. There's a pretty good chance you'll fix it in the process, or if not it's much easier for someone else to look at the problem.



Here is a example which I think shows the problem you describe:


import com.jme.app.SimpleGame;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jmex.effects.particles.ParticleFactory;
import com.jmex.effects.particles.ParticleMesh;


public class ScratchSimple extends SimpleGame {

   private boolean once = false;
   private ParticleMesh mesh = null;
   
   @Override
   protected void simpleInitGame() {
      cam.setLocation( new Vector3f(0 ,0 ,300f) );
      cam.update();
   }

   @Override
   protected void simpleUpdate() {
      if(!once) {
         once = true;
         
          mesh = ParticleFactory.buildParticles("particles", 300);
          mesh.setEmissionDirection( new Vector3f( 0f, 0f, 1f ) );
          mesh.setMaximumAngle( 0.0f );
          mesh.setSpeed( 0.5f );
          mesh.setMinimumLifeTime( 250.0f );
          mesh.setMaximumLifeTime( 500.0f );
          mesh.setStartSize( 1.6f );
          mesh.setEndSize( 5.0f );
          mesh.setStartColor( new ColorRGBA( 1.0f, 1.0f, 1.0f, 1.0f ) );
          mesh.setEndColor( new ColorRGBA( 0.6f, 0.2f, 0.0f, 0.0f ) );
          mesh.setInitialVelocity( 0.5f );

          rootNode.attachChild(mesh);
          mesh.setLocalTranslation(100, 0, 0);
          //mesh.updateGeometricState(0, true);
          mesh.forceRespawn();
          mesh.warmUp( 60 );
         
           
          mesh.updateGeometricState(0, true);
      }
   }
   
   /**
    * @param args
    */
   public static void main(String[] args) {
      ScratchSimple app = new ScratchSimple();
      app.setConfigShowMode(ConfigShowMode.AlwaysShow);
      app.start();
   }

}



If you uncomment the updateGeometricState that should fix the problem. If this is the same problem maybe that will give you some ideas. Probably you have warmed it up and updated before setting its location and updating. This will spawn some particles at the origin.

THANK YOU!



I used these Commands AFTER attaching the Particles to the rocket node!



    mesh.updateGeometricState(0, true);

    mesh.forceRespawn();





THANK YOU!



You just rescued my sanity!