[Solved]ParticleEmitter fixes

Hi.

The recent changes done to the ParticleEmitter class seems to have broken some things when loading/cloning them. Here are my fixes:

Sorry if i have misunderstood something and it should be handled in another way.


  1. read() must initialize the particleMesh. I pass numParticles as the second variable.
  2. rather than using “imagesX =” setImagesX()" and setImagesY()" must be used due to the changes related to the particleMesh.



    (A separate thing: the constructor now initializes the particleMesh with “particles.length” which is “null” at that point, is this correct?)

    [java]@Override

    public void read(JmeImporter im) throws IOException{

    super.read(im);

    InputCapsule ic = im.getCapsule(this);

    shape = (EmitterShape) ic.readSavable(“shape”, DEFAULT_SHAPE);

    meshType = ic.readEnum(“meshType”, ParticleMesh.Type.class, ParticleMesh.Type.Triangle);



    int numParticles = ic.readInt(“numParticles”, 0);

    setNumParticles(numParticles);



    switch (meshType){

    case Point:

    particleMesh = new ParticlePointMesh();

    setMesh(particleMesh);

    break;

    case Triangle:

    particleMesh = new ParticleTriMesh();

    setMesh(particleMesh);

    break;

    default:

    throw new IllegalStateException("Unrecognized particle type: "+meshType);

    }

    particleMesh.initParticleData(this, numParticles);







    enabled = ic.readBoolean(“enabled”, true);

    particlesPerSec = ic.readFloat(“particlesPerSec”, 0);

    lowLife = ic.readFloat(“lowLife”, 0);

    highLife = ic.readFloat(“highLife”, 0);

    gravity = ic.readFloat(“gravity”, 0);

    variation = ic.readFloat(“variation”, 0);

    setImagesX(ic.readInt(“imagesX”, 1));

    setImagesY(ic.readInt(“imagesY”, 1));



    startVel = (Vector3f) ic.readSavable(“startVel”, null);

    startColor = (ColorRGBA) ic.readSavable(“startColor”, null);

    endColor = (ColorRGBA) ic.readSavable(“endColor”, null);

    startSize = ic.readFloat(“startSize”, 0);

    endSize = ic.readFloat(“endSize”, 0);

    worldSpace = ic.readBoolean(“worldSpace”, false);

    facingVelocity = ic.readBoolean(“facingVelocity”, false);

    selectRandomImage = ic.readBoolean(“selectRandomImage”, false);

    randomAngle = ic.readBoolean(“randomAngle”, false);

    rotateSpeed = ic.readFloat(“rotateSpeed”, 0);

    }[/java]



    Same goes for clone(). Using clone.setImagesX(imagesX); and clone.setImagesY(imagesY);

    Also, clone() still seems to be missing some definitions that are necessary for my particle emitters to be correct, so i’m submitting my complete clone() method.

    [java]@Override

    public ParticleEmitter clone(){

    ParticleEmitter clone = (ParticleEmitter) super.clone();

    clone.shape = shape.deepClone();

    clone.setNumParticles(particles.length);

    clone.startVel = startVel.clone();

    clone.faceNormal = faceNormal.clone();

    clone.startColor = startColor.clone();

    clone.endColor = endColor.clone();

    clone.controls.add(clone);

    clone.cullHint = cullHint;

    clone.endSize = endSize;

    clone.facingVelocity = facingVelocity;

    clone.gravity = gravity;

    clone.highLife = highLife;

    clone.ignoreTransform = ignoreTransform;

    clone.worldSpace = worldSpace;

    clone.lowLife = lowLife;

    clone.particlesPerSec = particlesPerSec;

    clone.randomAngle = randomAngle;

    clone.rotateSpeed = rotateSpeed;

    clone.selectRandomImage = selectRandomImage;

    clone.variation = variation;

    clone.material = material;

    clone.setImagesX(imagesX);

    clone.setImagesY(imagesY);

    //clone.imagesX = imagesX;

    //clone.imagesY = imagesY;

    return clone;

    }[/java]



    I’m still investigating some other issues related to ParticleEmitter.java.
  • Some of my particles now move way faster than before.
  • No particle emitters emit anything when viewing them in the SceneComposer.
  • One of my particle emitters have disappeared completely when viewed in the SceneComposer.

I can confirm the issues in SceneComposer, but @nehon just fixed something in the particle shader, didnt check yet if it solved the problems.

uhhh nope…

Krill committed a fix to the emitter culling problem…but i didn’t…

Anyway i’ll look into this

Any update on particle emitters in the scene composer?

Something’s happened lately that changed the particles even more, and i would like to tweak them again using the scenecomposer.

New issue:

  • Edited out.



    Edit: It seems the new issue reported was caused by my matdef not having been updated properly (has Texture in one place, and m_Texture in Defines{}). Anyway, the rest still stands. :slight_smile:



    I noticed this issue in the SceneComposer. It could be caused by my changes to the ParticleEmitter, but it’s interesting to see if others have it too: