159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/*
259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Copyright (c) 2009-2010 jMonkeyEngine
359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * All rights reserved.
459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Redistribution and use in source and binary forms, with or without
659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * modification, are permitted provided that the following conditions are
759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * met:
859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Redistributions of source code must retain the above copyright
1059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   notice, this list of conditions and the following disclaimer.
1159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
1259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Redistributions in binary form must reproduce the above copyright
1359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   notice, this list of conditions and the following disclaimer in the
1459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   documentation and/or other materials provided with the distribution.
1559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
1659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
1759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   may be used to endorse or promote products derived from this software
1859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   without specific prior written permission.
1959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
2059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
2459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */
3259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
3359b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapackage jme3test.effect;
3459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
3559b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.app.SimpleApplication;
3659b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.effect.ParticleEmitter;
3759b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.effect.ParticleMesh.Type;
3859b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.effect.shapes.EmitterSphereShape;
3959b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.material.Material;
4059b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.math.ColorRGBA;
4159b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.math.FastMath;
4259b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.math.Quaternion;
4359b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.math.Vector3f;
4459b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.scene.Node;
4559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
4659b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapublic class TestExplosionEffect extends SimpleApplication {
4759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
4859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private float time = 0;
4959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private int state = 0;
5059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private Node explosionEffect = new Node("explosionFX");
5159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private ParticleEmitter flame, flash, spark, roundspark, smoketrail, debris,
5259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                            shockwave;
5359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
5459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
5559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private static final int COUNT_FACTOR = 1;
5659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private static final float COUNT_FACTOR_F = 1f;
5759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
5859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private static final boolean POINT_SPRITE = true;
5959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private static final Type EMITTER_TYPE = POINT_SPRITE ? Type.Point : Type.Triangle;
6059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
6159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public static void main(String[] args){
6259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        TestExplosionEffect app = new TestExplosionEffect();
6359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        app.start();
6459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
6559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
6659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private void createFlame(){
6759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flame = new ParticleEmitter("Flame", EMITTER_TYPE, 32 * COUNT_FACTOR);
6859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flame.setSelectRandomImage(true);
6959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flame.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, (float) (1f / COUNT_FACTOR_F)));
7059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flame.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f));
7159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flame.setStartSize(1.3f);
7259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flame.setEndSize(2f);
7359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flame.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
7459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flame.setParticlesPerSec(0);
7559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flame.setGravity(0, -5, 0);
7659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flame.setLowLife(.4f);
7759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flame.setHighLife(.5f);
7859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flame.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 7, 0));
7959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flame.getParticleInfluencer().setVelocityVariation(1f);
8059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flame.setImagesX(2);
8159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flame.setImagesY(2);
8259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
8359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
8459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        mat.setBoolean("PointSprite", POINT_SPRITE);
8559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flame.setMaterial(mat);
8659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        explosionEffect.attachChild(flame);
8759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
8859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
8959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private void createFlash(){
9059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flash = new ParticleEmitter("Flash", EMITTER_TYPE, 24 * COUNT_FACTOR);
9159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flash.setSelectRandomImage(true);
9259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flash.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, (float) (1f / COUNT_FACTOR_F)));
9359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flash.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
9459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flash.setStartSize(.1f);
9559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flash.setEndSize(3.0f);
9659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flash.setShape(new EmitterSphereShape(Vector3f.ZERO, .05f));
9759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flash.setParticlesPerSec(0);
9859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flash.setGravity(0, 0, 0);
9959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flash.setLowLife(.2f);
10059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flash.setHighLife(.2f);
10159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flash.setInitialVelocity(new Vector3f(0, 5f, 0));
10259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flash.setVelocityVariation(1);
10359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flash.setImagesX(2);
10459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flash.setImagesY(2);
10559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
10659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flash.png"));
10759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        mat.setBoolean("PointSprite", POINT_SPRITE);
10859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flash.setMaterial(mat);
10959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        explosionEffect.attachChild(flash);
11059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
11159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
11259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private void createRoundSpark(){
11359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        roundspark = new ParticleEmitter("RoundSpark", EMITTER_TYPE, 20 * COUNT_FACTOR);
11459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        roundspark.setStartColor(new ColorRGBA(1f, 0.29f, 0.34f, (float) (1.0 / COUNT_FACTOR_F)));
11559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        roundspark.setEndColor(new ColorRGBA(0, 0, 0, (float) (0.5f / COUNT_FACTOR_F)));
11659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        roundspark.setStartSize(1.2f);
11759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        roundspark.setEndSize(1.8f);
11859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        roundspark.setShape(new EmitterSphereShape(Vector3f.ZERO, 2f));
11959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        roundspark.setParticlesPerSec(0);
12059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        roundspark.setGravity(0, -.5f, 0);
12159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        roundspark.setLowLife(1.8f);
12259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        roundspark.setHighLife(2f);
12359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        roundspark.setInitialVelocity(new Vector3f(0, 3, 0));
12459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        roundspark.setVelocityVariation(.5f);
12559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        roundspark.setImagesX(1);
12659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        roundspark.setImagesY(1);
12759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
12859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/roundspark.png"));
12959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        mat.setBoolean("PointSprite", POINT_SPRITE);
13059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        roundspark.setMaterial(mat);
13159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        explosionEffect.attachChild(roundspark);
13259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
13359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
13459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private void createSpark(){
13559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        spark = new ParticleEmitter("Spark", Type.Triangle, 30 * COUNT_FACTOR);
13659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        spark.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, (float) (1.0f / COUNT_FACTOR_F)));
13759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        spark.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
13859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        spark.setStartSize(.5f);
13959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        spark.setEndSize(.5f);
14059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        spark.setFacingVelocity(true);
14159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        spark.setParticlesPerSec(0);
14259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        spark.setGravity(0, 5, 0);
14359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        spark.setLowLife(1.1f);
14459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        spark.setHighLife(1.5f);
14559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        spark.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 20, 0));
14659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        spark.getParticleInfluencer().setVelocityVariation(1);
14759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        spark.setImagesX(1);
14859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        spark.setImagesY(1);
14959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
15059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/spark.png"));
15159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        spark.setMaterial(mat);
15259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        explosionEffect.attachChild(spark);
15359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
15459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
15559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private void createSmokeTrail(){
15659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        smoketrail = new ParticleEmitter("SmokeTrail", Type.Triangle, 22 * COUNT_FACTOR);
15759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        smoketrail.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, (float) (1.0f / COUNT_FACTOR_F)));
15859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        smoketrail.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
15959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        smoketrail.setStartSize(.2f);
16059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        smoketrail.setEndSize(1f);
16159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
16259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta//        smoketrail.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
16359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        smoketrail.setFacingVelocity(true);
16459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        smoketrail.setParticlesPerSec(0);
16559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        smoketrail.setGravity(0, 1, 0);
16659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        smoketrail.setLowLife(.4f);
16759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        smoketrail.setHighLife(.5f);
16859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        smoketrail.setInitialVelocity(new Vector3f(0, 12, 0));
16959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        smoketrail.setVelocityVariation(1);
17059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        smoketrail.setImagesX(1);
17159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        smoketrail.setImagesY(3);
17259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
17359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/smoketrail.png"));
17459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        smoketrail.setMaterial(mat);
17559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        explosionEffect.attachChild(smoketrail);
17659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
17759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
17859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private void createDebris(){
17959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debris = new ParticleEmitter("Debris", Type.Triangle, 15 * COUNT_FACTOR);
18059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debris.setSelectRandomImage(true);
18159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debris.setRandomAngle(true);
18259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debris.setRotateSpeed(FastMath.TWO_PI * 4);
18359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debris.setStartColor(new ColorRGBA(1f, 0.59f, 0.28f, (float) (1.0f / COUNT_FACTOR_F)));
18459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debris.setEndColor(new ColorRGBA(.5f, 0.5f, 0.5f, 0f));
18559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debris.setStartSize(.2f);
18659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debris.setEndSize(.2f);
18759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
18859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta//        debris.setShape(new EmitterSphereShape(Vector3f.ZERO, .05f));
18959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debris.setParticlesPerSec(0);
19059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debris.setGravity(0, 12f, 0);
19159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debris.setLowLife(1.4f);
19259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debris.setHighLife(1.5f);
19359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debris.setInitialVelocity(new Vector3f(0, 15, 0));
19459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debris.setVelocityVariation(.60f);
19559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debris.setImagesX(3);
19659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debris.setImagesY(3);
19759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
19859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/Debris.png"));
19959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debris.setMaterial(mat);
20059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        explosionEffect.attachChild(debris);
20159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
20259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
20359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private void createShockwave(){
20459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        shockwave = new ParticleEmitter("Shockwave", Type.Triangle, 1 * COUNT_FACTOR);
20559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta//        shockwave.setRandomAngle(true);
20659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        shockwave.setFaceNormal(Vector3f.UNIT_Y);
20759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        shockwave.setStartColor(new ColorRGBA(.48f, 0.17f, 0.01f, (float) (.8f / COUNT_FACTOR_F)));
20859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        shockwave.setEndColor(new ColorRGBA(.48f, 0.17f, 0.01f, 0f));
20959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
21059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        shockwave.setStartSize(0f);
21159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        shockwave.setEndSize(7f);
21259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
21359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        shockwave.setParticlesPerSec(0);
21459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        shockwave.setGravity(0, 0, 0);
21559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        shockwave.setLowLife(0.5f);
21659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        shockwave.setHighLife(0.5f);
21759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        shockwave.setInitialVelocity(new Vector3f(0, 0, 0));
21859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        shockwave.setVelocityVariation(0f);
21959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        shockwave.setImagesX(1);
22059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        shockwave.setImagesY(1);
22159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
22259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/shockwave.png"));
22359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        shockwave.setMaterial(mat);
22459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        explosionEffect.attachChild(shockwave);
22559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
22659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
22759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    @Override
22859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public void simpleInitApp() {
22959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        createFlame();
23059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        createFlash();
23159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        createSpark();
23259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        createRoundSpark();
23359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        createSmokeTrail();
23459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        createDebris();
23559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        createShockwave();
23659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        explosionEffect.setLocalScale(0.5f);
23759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        renderManager.preloadScene(explosionEffect);
23859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
23959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        cam.setLocation(new Vector3f(0, 3.5135868f, 10));
24059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        cam.setRotation(new Quaternion(1.5714673E-4f, 0.98696727f, -0.16091813f, 9.6381607E-4f));
24159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
24259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        rootNode.attachChild(explosionEffect);
24359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
24459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
24559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    @Override
24659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public void simpleUpdate(float tpf){
24759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        time += tpf / speed;
24859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        if (time > 1f && state == 0){
24959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            flash.emitAllParticles();
25059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            spark.emitAllParticles();
25159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            smoketrail.emitAllParticles();
25259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            debris.emitAllParticles();
25359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            shockwave.emitAllParticles();
25459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            state++;
25559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        }
25659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        if (time > 1f + .05f / speed && state == 1){
25759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            flame.emitAllParticles();
25859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            roundspark.emitAllParticles();
25959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            state++;
26059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        }
26159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
26259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        // rewind the effect
26359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        if (time > 5 / speed && state == 2){
26459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            state = 0;
26559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            time = 0;
26659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
26759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            flash.killAllParticles();
26859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            spark.killAllParticles();
26959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            smoketrail.killAllParticles();
27059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            debris.killAllParticles();
27159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            flame.killAllParticles();
27259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            roundspark.killAllParticles();
27359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            shockwave.killAllParticles();
27459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        }
27559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
27659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
27759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta}
278