Search in sources :

Example 11 with ParticleEmitter

use of com.jme3.effect.ParticleEmitter in project jmonkeyengine by jMonkeyEngine.

the class TestSoftParticles method createParticles.

private void createParticles() {
    Material material = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    material.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
    // 
    material.setFloat("Softness", 3f);
    //Fire
    ParticleEmitter fire = new ParticleEmitter("Fire", ParticleMesh.Type.Triangle, 30);
    fire.setMaterial(material);
    fire.setShape(new EmitterSphereShape(Vector3f.ZERO, 0.1f));
    fire.setImagesX(2);
    // 2x2 texture animation
    fire.setImagesY(2);
    // red
    fire.setEndColor(new ColorRGBA(1f, 0f, 0f, 1f));
    // yellow
    fire.setStartColor(new ColorRGBA(1f, 1f, 0f, 0.5f));
    fire.setStartSize(0.6f);
    fire.setEndSize(0.01f);
    fire.setGravity(0, -0.3f, 0);
    fire.setLowLife(0.5f);
    fire.setHighLife(3f);
    fire.setLocalTranslation(0, 0.2f, 0);
    particleNode.attachChild(fire);
    ParticleEmitter smoke = new ParticleEmitter("Smoke", ParticleMesh.Type.Triangle, 30);
    smoke.setMaterial(material);
    smoke.setShape(new EmitterSphereShape(Vector3f.ZERO, 5));
    smoke.setImagesX(1);
    // 2x2 texture animation
    smoke.setImagesY(1);
    // dark gray
    smoke.setStartColor(new ColorRGBA(0.1f, 0.1f, 0.1f, 1f));
    // gray      
    smoke.setEndColor(new ColorRGBA(0.5f, 0.5f, 0.5f, 0.3f));
    smoke.setStartSize(3f);
    smoke.setEndSize(5f);
    smoke.setGravity(0, -0.001f, 0);
    smoke.setLowLife(100f);
    smoke.setHighLife(100f);
    smoke.setLocalTranslation(0, 0.1f, 0);
    smoke.emitAllParticles();
    particleNode.attachChild(smoke);
}
Also used : ParticleEmitter(com.jme3.effect.ParticleEmitter) ColorRGBA(com.jme3.math.ColorRGBA) EmitterSphereShape(com.jme3.effect.shapes.EmitterSphereShape) Material(com.jme3.material.Material)

Example 12 with ParticleEmitter

use of com.jme3.effect.ParticleEmitter in project jmonkeyengine by jMonkeyEngine.

the class BombControl method prepareEffect.

private void prepareEffect(AssetManager assetManager) {
    int COUNT_FACTOR = 1;
    float COUNT_FACTOR_F = 1f;
    effect = new ParticleEmitter("Flame", Type.Triangle, 32 * COUNT_FACTOR);
    effect.setSelectRandomImage(true);
    effect.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, (float) (1f / COUNT_FACTOR_F)));
    effect.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f));
    effect.setStartSize(1.3f);
    effect.setEndSize(2f);
    effect.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
    effect.setParticlesPerSec(0);
    effect.setGravity(0, -5f, 0);
    effect.setLowLife(.4f);
    effect.setHighLife(.5f);
    effect.setInitialVelocity(new Vector3f(0, 7, 0));
    effect.setVelocityVariation(1f);
    effect.setImagesX(2);
    effect.setImagesY(2);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
    effect.setMaterial(mat);
}
Also used : ParticleEmitter(com.jme3.effect.ParticleEmitter) ColorRGBA(com.jme3.math.ColorRGBA) Vector3f(com.jme3.math.Vector3f) EmitterSphereShape(com.jme3.effect.shapes.EmitterSphereShape) Material(com.jme3.material.Material)

Example 13 with ParticleEmitter

use of com.jme3.effect.ParticleEmitter in project jmonkeyengine by jMonkeyEngine.

the class ParticleEmitter method read.

@Override
public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule ic = im.getCapsule(this);
    shape = (EmitterShape) ic.readSavable("shape", DEFAULT_SHAPE);
    if (shape == DEFAULT_SHAPE) {
        // Prevent reference to static
        shape = shape.deepClone();
    }
    meshType = ic.readEnum("meshType", ParticleMesh.Type.class, ParticleMesh.Type.Triangle);
    int numParticles = ic.readInt("numParticles", 0);
    enabled = ic.readBoolean("enabled", true);
    particlesPerSec = ic.readFloat("particlesPerSec", 0);
    lowLife = ic.readFloat("lowLife", 0);
    highLife = ic.readFloat("highLife", 0);
    gravity = (Vector3f) ic.readSavable("gravity", null);
    imagesX = ic.readInt("imagesX", 1);
    imagesY = ic.readInt("imagesY", 1);
    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);
    this.setIgnoreTransform(worldSpace);
    facingVelocity = ic.readBoolean("facingVelocity", false);
    faceNormal = (Vector3f) ic.readSavable("faceNormal", new Vector3f(Vector3f.NAN));
    selectRandomImage = ic.readBoolean("selectRandomImage", false);
    randomAngle = ic.readBoolean("randomAngle", false);
    rotateSpeed = ic.readFloat("rotateSpeed", 0);
    switch(meshType) {
        case Point:
            particleMesh = new ParticlePointMesh();
            this.setMesh(particleMesh);
            break;
        case Triangle:
            particleMesh = new ParticleTriMesh();
            this.setMesh(particleMesh);
            break;
        default:
            throw new IllegalStateException("Unrecognized particle type: " + meshType);
    }
    this.setNumParticles(numParticles);
    //        particleMesh.initParticleData(this, particles.length);
    //        particleMesh.setImagesXY(imagesX, imagesY);
    particleInfluencer = (ParticleInfluencer) ic.readSavable("influencer", DEFAULT_INFLUENCER);
    if (particleInfluencer == DEFAULT_INFLUENCER) {
        particleInfluencer = particleInfluencer.clone();
    }
    if (im.getFormatVersion() == 0) {
        // find it in the controls and take it out, then add the proper one in
        for (int i = 0; i < controls.size(); i++) {
            Object obj = controls.get(i);
            if (obj instanceof ParticleEmitter) {
                controls.remove(i);
                // now add the proper one in
                controls.add(new ParticleEmitterControl(this));
                break;
            }
        }
        // compatability before gravity was not a vector but a float
        if (gravity == null) {
            gravity = new Vector3f();
            gravity.y = ic.readFloat("gravity", 0);
        }
    } else {
        // since the parentEmitter is not loaded, it must be
        // loaded separately
        control = getControl(ParticleEmitterControl.class);
        control.parentEmitter = this;
    }
}
Also used : Type(com.jme3.effect.ParticleMesh.Type) InputCapsule(com.jme3.export.InputCapsule) Vector3f(com.jme3.math.Vector3f)

Example 14 with ParticleEmitter

use of com.jme3.effect.ParticleEmitter in project jmonkeyengine by jMonkeyEngine.

the class ParticlePointMesh method initParticleData.

@Override
public void initParticleData(ParticleEmitter emitter, int numParticles) {
    setMode(Mode.Points);
    this.emitter = emitter;
    // set positions
    FloatBuffer pb = BufferUtils.createVector3Buffer(numParticles);
    //if the buffer is already set only update the data
    VertexBuffer buf = getBuffer(VertexBuffer.Type.Position);
    if (buf != null) {
        buf.updateData(pb);
    } else {
        VertexBuffer pvb = new VertexBuffer(VertexBuffer.Type.Position);
        pvb.setupData(Usage.Stream, 3, Format.Float, pb);
        setBuffer(pvb);
    }
    // set colors
    ByteBuffer cb = BufferUtils.createByteBuffer(numParticles * 4);
    buf = getBuffer(VertexBuffer.Type.Color);
    if (buf != null) {
        buf.updateData(cb);
    } else {
        VertexBuffer cvb = new VertexBuffer(VertexBuffer.Type.Color);
        cvb.setupData(Usage.Stream, 4, Format.UnsignedByte, cb);
        cvb.setNormalized(true);
        setBuffer(cvb);
    }
    // set sizes
    FloatBuffer sb = BufferUtils.createFloatBuffer(numParticles);
    buf = getBuffer(VertexBuffer.Type.Size);
    if (buf != null) {
        buf.updateData(sb);
    } else {
        VertexBuffer svb = new VertexBuffer(VertexBuffer.Type.Size);
        svb.setupData(Usage.Stream, 1, Format.Float, sb);
        setBuffer(svb);
    }
    // set UV-scale
    FloatBuffer tb = BufferUtils.createFloatBuffer(numParticles * 4);
    buf = getBuffer(VertexBuffer.Type.TexCoord);
    if (buf != null) {
        buf.updateData(tb);
    } else {
        VertexBuffer tvb = new VertexBuffer(VertexBuffer.Type.TexCoord);
        tvb.setupData(Usage.Stream, 4, Format.Float, tb);
        setBuffer(tvb);
    }
    updateCounts();
}
Also used : VertexBuffer(com.jme3.scene.VertexBuffer) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 15 with ParticleEmitter

use of com.jme3.effect.ParticleEmitter in project jmonkeyengine by jMonkeyEngine.

the class ParticleTriMesh method initParticleData.

//    private Particle[] particlesCopy;
@Override
public void initParticleData(ParticleEmitter emitter, int numParticles) {
    setMode(Mode.Triangles);
    this.emitter = emitter;
    //        particlesCopy = new Particle[numParticles];
    // set positions
    FloatBuffer pb = BufferUtils.createVector3Buffer(numParticles * 4);
    // if the buffer is already set only update the data
    VertexBuffer buf = getBuffer(VertexBuffer.Type.Position);
    if (buf != null) {
        buf.updateData(pb);
    } else {
        VertexBuffer pvb = new VertexBuffer(VertexBuffer.Type.Position);
        pvb.setupData(Usage.Stream, 3, Format.Float, pb);
        setBuffer(pvb);
    }
    // set colors
    ByteBuffer cb = BufferUtils.createByteBuffer(numParticles * 4 * 4);
    buf = getBuffer(VertexBuffer.Type.Color);
    if (buf != null) {
        buf.updateData(cb);
    } else {
        VertexBuffer cvb = new VertexBuffer(VertexBuffer.Type.Color);
        cvb.setupData(Usage.Stream, 4, Format.UnsignedByte, cb);
        cvb.setNormalized(true);
        setBuffer(cvb);
    }
    // set texcoords
    FloatBuffer tb = BufferUtils.createVector2Buffer(numParticles * 4);
    uniqueTexCoords = false;
    for (int i = 0; i < numParticles; i++) {
        tb.put(0f).put(1f);
        tb.put(1f).put(1f);
        tb.put(0f).put(0f);
        tb.put(1f).put(0f);
    }
    tb.flip();
    buf = getBuffer(VertexBuffer.Type.TexCoord);
    if (buf != null) {
        buf.updateData(tb);
    } else {
        VertexBuffer tvb = new VertexBuffer(VertexBuffer.Type.TexCoord);
        tvb.setupData(Usage.Static, 2, Format.Float, tb);
        setBuffer(tvb);
    }
    // set indices
    ShortBuffer ib = BufferUtils.createShortBuffer(numParticles * 6);
    for (int i = 0; i < numParticles; i++) {
        int startIdx = (i * 4);
        // triangle 1
        ib.put((short) (startIdx + 1)).put((short) (startIdx + 0)).put((short) (startIdx + 2));
        // triangle 2
        ib.put((short) (startIdx + 1)).put((short) (startIdx + 2)).put((short) (startIdx + 3));
    }
    ib.flip();
    buf = getBuffer(VertexBuffer.Type.Index);
    if (buf != null) {
        buf.updateData(ib);
    } else {
        VertexBuffer ivb = new VertexBuffer(VertexBuffer.Type.Index);
        ivb.setupData(Usage.Static, 3, Format.UnsignedShort, ib);
        setBuffer(ivb);
    }
    updateCounts();
}
Also used : VertexBuffer(com.jme3.scene.VertexBuffer) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) ShortBuffer(java.nio.ShortBuffer)

Aggregations

ParticleEmitter (com.jme3.effect.ParticleEmitter)20 Material (com.jme3.material.Material)17 Vector3f (com.jme3.math.Vector3f)15 ColorRGBA (com.jme3.math.ColorRGBA)13 EmitterSphereShape (com.jme3.effect.shapes.EmitterSphereShape)7 Spatial (com.jme3.scene.Spatial)4 ActionListener (com.jme3.input.controls.ActionListener)3 KeyTrigger (com.jme3.input.controls.KeyTrigger)3 EmitterMeshVertexShape (com.jme3.effect.shapes.EmitterMeshVertexShape)2 InputCapsule (com.jme3.export.InputCapsule)2 Geometry (com.jme3.scene.Geometry)2 Node (com.jme3.scene.Node)2 VertexBuffer (com.jme3.scene.VertexBuffer)2 ByteBuffer (java.nio.ByteBuffer)2 FloatBuffer (java.nio.FloatBuffer)2 Type (com.jme3.effect.ParticleMesh.Type)1 EmptyParticleInfluencer (com.jme3.effect.influencers.EmptyParticleInfluencer)1 NewtonianParticleInfluencer (com.jme3.effect.influencers.NewtonianParticleInfluencer)1 ParticleInfluencer (com.jme3.effect.influencers.ParticleInfluencer)1 EmitterBoxShape (com.jme3.effect.shapes.EmitterBoxShape)1