diff --git a/engine/src/test/jme3test/effect/TestSoftParticles.java b/engine/src/test/jme3test/effect/TestSoftParticles.java index f0f0a2a8b..3d8f96d65 100644 --- a/engine/src/test/jme3test/effect/TestSoftParticles.java +++ b/engine/src/test/jme3test/effect/TestSoftParticles.java @@ -36,8 +36,10 @@ import com.jme3.effect.ParticleEmitter; import com.jme3.effect.ParticleMesh; import com.jme3.effect.shapes.EmitterSphereShape; import com.jme3.input.KeyInput; +import com.jme3.input.MouseInput; import com.jme3.input.controls.ActionListener; import com.jme3.input.controls.KeyTrigger; +import com.jme3.input.controls.MouseButtonTrigger; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.math.Quaternion; @@ -45,6 +47,7 @@ import com.jme3.math.Vector3f; import com.jme3.post.FilterPostProcessor; import com.jme3.post.filters.TranslucentBucketFilter; import com.jme3.scene.Geometry; +import com.jme3.scene.Node; import com.jme3.scene.shape.Box; /** @@ -56,6 +59,7 @@ public class TestSoftParticles extends SimpleApplication { private boolean softParticles = true; private FilterPostProcessor fpp; private TranslucentBucketFilter tbf; + private Node particleNode; public static void main(String[] args) { TestSoftParticles app = new TestSoftParticles(); @@ -93,47 +97,10 @@ public class TestSoftParticles extends SimpleApplication { fpp.addFilter(tbf); viewPort.addProcessor(fpp); - - Material material = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"); - material.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png")); + particleNode = new Node("particleNode"); + rootNode.attachChild(particleNode); - 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); - fire.setImagesY(2); // 2x2 texture animation - fire.setEndColor(new ColorRGBA(1f, 0f, 0f, 1f)); // red - fire.setStartColor(new ColorRGBA(1f, 1f, 0f, 0.5f)); // yellow - 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); - - rootNode.attachChild(fire); - - - ParticleEmitter smoke = new ParticleEmitter("Smoke", ParticleMesh.Type.Triangle, 30); - smoke.setMaterial(material); - smoke.setShape(new EmitterSphereShape(Vector3f.ZERO, 5)); - smoke.setImagesX(1); - smoke.setImagesY(1); // 2x2 texture animation - smoke.setStartColor(new ColorRGBA(0.1f, 0.1f, 0.1f,1f)); // dark gray - smoke.setEndColor(new ColorRGBA(0.5f, 0.5f, 0.5f, 0.3f)); // gray - 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(); - - rootNode.attachChild(smoke); + createParticles(); inputManager.addListener(new ActionListener() { @@ -151,6 +118,61 @@ public class TestSoftParticles extends SimpleApplication { } }, "toggle"); inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE)); + + // emit again + inputManager.addListener(new ActionListener() { + public void onAction(String name, boolean isPressed, float tpf) { + if(isPressed && name.equals("refire")) { + //fpp.removeFilter(tbf); // <-- add back in to fix + particleNode.detachAllChildren(); + createParticles(); + //fpp.addFilter(tbf); + } + } + }, "refire"); + inputManager.addMapping("refire", new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); + } + + 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); + fire.setImagesY(2); // 2x2 texture animation + fire.setEndColor(new ColorRGBA(1f, 0f, 0f, 1f)); // red + fire.setStartColor(new ColorRGBA(1f, 1f, 0f, 0.5f)); // yellow + 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); + smoke.setImagesY(1); // 2x2 texture animation + smoke.setStartColor(new ColorRGBA(0.1f, 0.1f, 0.1f,1f)); // dark gray + smoke.setEndColor(new ColorRGBA(0.5f, 0.5f, 0.5f, 0.3f)); // gray + 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); }