Search in sources :

Example 16 with ParticleEmitter

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

the class EffectTrack method findEmitter.

/**
     * recursive function responsible for finding the newly cloned Emitter
     *
     * @param spat
     * @return
     */
private ParticleEmitter findEmitter(Spatial spat) {
    if (spat instanceof ParticleEmitter) {
        //spat is a PArticleEmitter
        ParticleEmitter em = (ParticleEmitter) spat;
        //getting the UserData TrackInfo so check if it should be attached to this Track
        TrackInfo t = (TrackInfo) em.getUserData("TrackInfo");
        if (t != null && t.getTracks().contains(this)) {
            return em;
        }
        return null;
    } else if (spat instanceof Node) {
        for (Spatial child : ((Node) spat).getChildren()) {
            ParticleEmitter em = findEmitter(child);
            if (em != null) {
                return em;
            }
        }
    }
    return null;
}
Also used : ParticleEmitter(com.jme3.effect.ParticleEmitter) Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node)

Example 17 with ParticleEmitter

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

the class EffectTrack method read.

/**
     * Internal use only serialization
     *
     * @param im importer
     * @throws IOException Exception
     */
public void read(JmeImporter im) throws IOException {
    InputCapsule in = im.getCapsule(this);
    this.particlesPerSeconds = in.readFloat("particlesPerSeconds", 0);
    //reading the emitter even if the track will then reference its cloned counter part if it's loaded with the assetManager.
    //This also avoid null pointer exception if the model is not loaded via the AssetManager.
    emitter = (ParticleEmitter) in.readSavable("emitter", null);
    emitter.setParticlesPerSec(0);
    //if the emitter was saved with a KillParticleControl we remove it.
    //        Control c = emitter.getControl(KillParticleControl.class);
    //        if(c!=null){
    //            emitter.removeControl(c);
    //        }
    //emitter.removeControl(KillParticleControl.class);
    length = in.readFloat("length", length);
    startOffset = in.readFloat("startOffset", 0);
}
Also used : InputCapsule(com.jme3.export.InputCapsule)

Example 18 with ParticleEmitter

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

the class TranslucentBucketFilter method makeSoftParticleEmitter.

private void makeSoftParticleEmitter(Spatial scene, boolean enabled) {
    if (scene instanceof Node) {
        Node n = (Node) scene;
        for (Spatial child : n.getChildren()) {
            makeSoftParticleEmitter(child, enabled);
        }
    }
    if (scene instanceof ParticleEmitter) {
        ParticleEmitter emitter = (ParticleEmitter) scene;
        if (enabled) {
            enabledSoftParticles = enabled;
            emitter.getMaterial().selectTechnique("SoftParticles", renderManager);
            if (processor.getNumSamples() > 1) {
                emitter.getMaterial().setInt("NumSamplesDepth", processor.getNumSamples());
            }
            emitter.getMaterial().setTexture("DepthTexture", processor.getDepthTexture());
            emitter.setQueueBucket(RenderQueue.Bucket.Translucent);
            logger.log(Level.FINE, "Made particle Emitter {0} soft.", emitter.getName());
        } else {
            emitter.getMaterial().clearParam("DepthTexture");
            emitter.getMaterial().selectTechnique("Default", renderManager);
            // emitter.setQueueBucket(RenderQueue.Bucket.Transparent);
            logger.log(Level.FINE, "Particle Emitter {0} is not soft anymore.", emitter.getName());
        }
    }
}
Also used : ParticleEmitter(com.jme3.effect.ParticleEmitter) Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node)

Example 19 with ParticleEmitter

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

the class TestExplosionEffect method createFlame.

private void createFlame() {
    flame = new ParticleEmitter("Flame", EMITTER_TYPE, 32 * COUNT_FACTOR);
    flame.setSelectRandomImage(true);
    flame.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, (float) (1f / COUNT_FACTOR_F)));
    flame.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f));
    flame.setStartSize(1.3f);
    flame.setEndSize(2f);
    flame.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
    flame.setParticlesPerSec(0);
    flame.setGravity(0, -5, 0);
    flame.setLowLife(.4f);
    flame.setHighLife(.5f);
    flame.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 7, 0));
    flame.getParticleInfluencer().setVelocityVariation(1f);
    flame.setImagesX(2);
    flame.setImagesY(2);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
    mat.setBoolean("PointSprite", POINT_SPRITE);
    flame.setMaterial(mat);
    explosionEffect.attachChild(flame);
}
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 20 with ParticleEmitter

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

the class TestExplosionEffect method createFlash.

private void createFlash() {
    flash = new ParticleEmitter("Flash", EMITTER_TYPE, 24 * COUNT_FACTOR);
    flash.setSelectRandomImage(true);
    flash.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, (float) (1f / COUNT_FACTOR_F)));
    flash.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
    flash.setStartSize(.1f);
    flash.setEndSize(3.0f);
    flash.setShape(new EmitterSphereShape(Vector3f.ZERO, .05f));
    flash.setParticlesPerSec(0);
    flash.setGravity(0, 0, 0);
    flash.setLowLife(.2f);
    flash.setHighLife(.2f);
    flash.setInitialVelocity(new Vector3f(0, 5f, 0));
    flash.setVelocityVariation(1);
    flash.setImagesX(2);
    flash.setImagesY(2);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flash.png"));
    mat.setBoolean("PointSprite", POINT_SPRITE);
    flash.setMaterial(mat);
    explosionEffect.attachChild(flash);
}
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)

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