Problem with RenParticleEditor example!

Hi guys!



I recognize that particles still exist and remain local translation when you switch to smoke from jet!



How to solve this problem?



I got the same problem with my project! Scratching from head!  :?

Check this thread. I think you are talking about the same issue.

Actually, I want to see into how particles system works. When it initializes (render at first), It have always existed a flash point on screen for a short time. How to solve this problem?

In the editor, when you choose an example, you are simply applying new settings to the existing particles, so the particles that already exist will continue to exist and move in the world from where they are until they die.



The problem you've mentioned on here several times is because when you warmup, the particles are being created relative to the origin offset which is 0,0,0 at the time this happens.  What needs to happen is you need to move your particles to the correct starting location first, update it's world vectors, then warmup.  I'll see if I can make that easier.

Hi Renanse,



Thanks for your directions.



Once again, can you give me some more details (snippets) how to solve by your way!

it might be easier if you post a small test that is giving you problems and I'll show you how to correct it.

Here my snippet:



public static ParticleMesh makeBoiling(){

    Ring disk = new Ring(new Vector3f(0,0,0), new Vector3f(0,1,0), 1, 55);

   

    AlphaState as = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState();

        as.setBlendEnabled(true);

        as.setSrcFunction(AlphaState.SB_SRC_ALPHA);

        as.setDstFunction(AlphaState.DB_ONE);

        as.setTestFunction(AlphaState.TF_GREATER);

        as.setEnabled(true);

        as.setTestEnabled(true);

       

        ZBufferState zs = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();

        zs.setEnabled(true);

        zs.setWritable(false);

   

    ParticleMesh particles = ParticleFactory.buildParticles("particles", 350, ParticleMesh.ET_POINT);

        particles.setControlFlow(true);

        particles.setGeometry(disk);

        particles.setInitialVelocity(.01f);

        particles.getParticleController().setSpeed(.1f);

        particles.setEmissionDirection(new Vector3f(0, 1, 0));

        particles.setMinimumAngle(0.0f);

        particles.setMaximumAngle(0.210943952f);

        particles.setMinimumLifeTime(170);

        particles.setMaximumLifeTime(170.005f);

        particles.setStartColor(new ColorRGBA(1, 1, 1, 1));

        particles.setEndColor(new ColorRGBA(1, 1, 1, 0));

        particles.setStartSize(1f);

        particles.setEndSize(0.8f);

        particles.setReleaseVariance(1.2f);



        TextureState ts = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();

        URL url = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "bubble.jpg");

        ts.setTexture(TextureManager.loadTexture(url, Texture.EM_SPHERE, Texture.EM_SPHERE));

        ts.setEnabled(true);



        particles.setRenderState(ts);

        particles.setRenderState(as);

        particles.setRenderState(zs);

       

        particles.updateRenderState();

       

        return particles;

    }

Hi Renanse,



My problem is the same with http://www.jmonkeyengine.com/jmeforum/index.php?topic=7566.0

In addition, I give you an related image:







And here my snippet to make particle system (copy from TestParticleSystem class):



public static ParticleMesh makeBoiling(){

AlphaState as1 = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState();

as1.setBlendEnabled(true);

as1.setSrcFunction(AlphaState.SB_SRC_ALPHA);

as1.setDstFunction(AlphaState.DB_ONE);

as1.setTestEnabled(true);

as1.setTestFunction(AlphaState.TF_GREATER);

as1.setEnabled(true);



TextureState ts = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();

ts.setTexture(TextureManager.loadTexture(ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, “flaresmall.jpg”),

Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR));

ts.setEnabled(true);

   

    ParticleMesh pMesh = ParticleFactory.buildParticles(“particles”, 300);

pMesh.setEmissionDirection(new Vector3f(0, 1, 0));

pMesh.setInitialVelocity(.006f);

pMesh.setStartSize(2.5f);

pMesh.setEndSize(.5f);

pMesh.setMinimumLifeTime(1200f);

pMesh.setMaximumLifeTime(1400f);

pMesh.setStartColor(new ColorRGBA(1, 0, 0, 1));

pMesh.setEndColor(new ColorRGBA(0, 1, 0, 0));

pMesh.setMaximumAngle(360f * FastMath.DEG_TO_RAD);

pMesh.getParticleController().setControlFlow(false);



pMesh.setRenderState(ts);

pMesh.setRenderState(as1);

ZBufferState zstate = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();

zstate.setEnabled(false);

pMesh.setRenderState(zstate);



pMesh.setModelBound(new BoundingSphere());

pMesh.updateModelBound();



pMesh.setLocalTranslation(new Vector3f(30, 0, 30));

pMesh.setOriginOffset(new Vector3f(20, 0, 20));

pMesh.updateWorldVectors();

pMesh.warmUp(60);



return pMesh;

}

Here's a modified version of TestParticleSystem that simply adds a new particle system to the scene every 5 secs…  I don't see the problem you describe, but maybe you can change this code to produce it.



import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingSphere;
import com.jme.image.Texture;
import com.jme.math.FastMath;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.state.AlphaState;
import com.jme.scene.state.TextureState;
import com.jme.scene.state.ZBufferState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;
import com.jmex.effects.particles.ParticleFactory;
import com.jmex.effects.particles.ParticleMesh;

/**
 * @author Joshua Slack
 * @version $Id: TestParticleSystem.java,v 1.34 2006/07/06 22:22:18 nca Exp $
 */
public class TestParticleSystem2 extends SimpleGame {

  private ParticleMesh pMesh;
  private Vector3f currentPos = new Vector3f(), newPos = new Vector3f();
  private float frameRate = 0;

  public static void main(String[] args) {
    TestParticleSystem2 app = new TestParticleSystem2();
    app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
    app.start();
  }

  float time = 5;
  protected void simpleUpdate() {
    if (tpf > 1f) tpf = 1.0f; // do this to prevent a long pause at start

    if ( (int) currentPos.x == (int) newPos.x
        && (int) currentPos.y == (int) newPos.y
        && (int) currentPos.z == (int) newPos.z) {
      newPos.x = (float) Math.random() * 50 - 25;
      newPos.y = (float) Math.random() * 50 - 25;
      newPos.z = (float) Math.random() * 50 - 150;
    }

    frameRate = timer.getFrameRate() / 2;
    currentPos.x -= (currentPos.x - newPos.x)
        / frameRate;
    currentPos.y -= (currentPos.y - newPos.y)
        / frameRate;
    currentPos.z -= (currentPos.z - newPos.z)
        / frameRate;

    if (pMesh != null)
       pMesh.setOriginOffset(currentPos);

    time += tpf;
    if (time > 5) {
       time = 0;
        pMesh = makeBoiling();
        // attach this new particle mesh, leaving the old one orphaned.
        rootNode.attachChild(pMesh);
        pMesh.updateRenderState();
    }
  }

  protected void simpleInitGame() {
    display.setTitle("Particle System");
    lightState.setEnabled(false);

    AlphaState as1 = display.getRenderer().createAlphaState();
    as1.setBlendEnabled(true);
    as1.setSrcFunction(AlphaState.SB_SRC_ALPHA);
    as1.setDstFunction(AlphaState.DB_ONE);
    as1.setTestEnabled(true);
    as1.setTestFunction(AlphaState.TF_GREATER);
    as1.setEnabled(true);

    TextureState ts = display.getRenderer().createTextureState();
    ts.setTexture(
        TextureManager.loadTexture(
        TestParticleSystem2.class.getClassLoader().getResource(
        "jmetest/data/texture/flaresmall.jpg"),
        Texture.MM_LINEAR_LINEAR,
        Texture.FM_LINEAR));
    ts.setEnabled(true);

    rootNode.setRenderState(ts);
    rootNode.setRenderState(as1);
  }
 
  public static ParticleMesh makeBoiling(){

            ParticleMesh pMesh = ParticleFactory.buildParticles("particles", 300);
           pMesh.setEmissionDirection(new Vector3f(0, 1, 0));
           pMesh.setInitialVelocity(.006f);
           pMesh.setStartSize(2.5f);
           pMesh.setEndSize(.5f);
           pMesh.setMinimumLifeTime(1200f);
           pMesh.setMaximumLifeTime(1400f);
           pMesh.setStartColor(new ColorRGBA(1, 0, 0, 1));
           pMesh.setEndColor(new ColorRGBA(0, 1, 0, 0));
           pMesh.setMaximumAngle(360f * FastMath.DEG_TO_RAD);
           pMesh.getParticleController().setControlFlow(false);

           ZBufferState zstate = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
           zstate.setEnabled(false);
           pMesh.setRenderState(zstate);

           pMesh.setModelBound(new BoundingSphere());
           pMesh.updateModelBound();

           pMesh.setLocalTranslation(new Vector3f(30, 0, 30));
           pMesh.setOriginOffset(new Vector3f(20, 0, 20));
           pMesh.updateWorldVectors();
           pMesh.warmUp(60);
          
           return pMesh;
     }
}

My class extends from GameState class. Maybe something wrong when update() method is called!

Ah ha!



Hi Renanse,



I found that It's ok when I implement my game on a PC with better performance (better graphic card)!



Can you give some advice?