1/* 2 * To change this template, choose Tools | Templates 3 * and open the template in the editor. 4 */ 5package jme3test.effect; 6 7import com.jme3.app.SimpleApplication; 8import com.jme3.effect.ParticleEmitter; 9import com.jme3.effect.ParticleMesh; 10import com.jme3.effect.shapes.EmitterSphereShape; 11import com.jme3.input.KeyInput; 12import com.jme3.input.controls.ActionListener; 13import com.jme3.input.controls.KeyTrigger; 14import com.jme3.material.Material; 15import com.jme3.math.ColorRGBA; 16import com.jme3.math.Quaternion; 17import com.jme3.math.Vector3f; 18import com.jme3.post.FilterPostProcessor; 19import com.jme3.post.filters.TranslucentBucketFilter; 20import com.jme3.scene.Geometry; 21import com.jme3.scene.shape.Box; 22 23/** 24 * 25 * @author Nehon 26 */ 27public class TestSoftParticles extends SimpleApplication { 28 29 private boolean softParticles = true; 30 private FilterPostProcessor fpp; 31 private TranslucentBucketFilter tbf; 32 33 public static void main(String[] args) { 34 TestSoftParticles app = new TestSoftParticles(); 35 app.start(); 36 } 37 38 @Override 39 public void simpleInitApp() { 40 41 cam.setLocation(new Vector3f(-7.2221026f, 4.1183004f, 7.759811f)); 42 cam.setRotation(new Quaternion(0.06152846f, 0.91236454f, -0.1492115f, 0.37621948f)); 43 44 flyCam.setMoveSpeed(10); 45 46 47 // -------- floor 48 Box b = new Box(Vector3f.ZERO, 10, 0.1f, 10); 49 Geometry geom = new Geometry("Box", b); 50 Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); 51 mat.setColor("Color", ColorRGBA.Gray); 52 mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg")); 53 geom.setMaterial(mat); 54 rootNode.attachChild(geom); 55 56 Box b2 = new Box(Vector3f.ZERO, 1, 1, 1); 57 Geometry geom2 = new Geometry("Box", b2); 58 Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); 59 mat2.setColor("Color", ColorRGBA.DarkGray); 60 geom2.setMaterial(mat2); 61 rootNode.attachChild(geom2); 62 geom2.setLocalScale(0.1f, 0.2f, 1); 63 64 fpp = new FilterPostProcessor(assetManager); 65 tbf = new TranslucentBucketFilter(true); 66 fpp.addFilter(tbf); 67 viewPort.addProcessor(fpp); 68 69 70 Material material = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"); 71 material.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png")); 72 73 material.setFloat("Softness", 3f); // 74 75 76 //Fire 77 ParticleEmitter fire = new ParticleEmitter("Fire", ParticleMesh.Type.Triangle, 30); 78 fire.setMaterial(material); 79 fire.setShape(new EmitterSphereShape(Vector3f.ZERO, 0.1f)); 80 fire.setImagesX(2); 81 fire.setImagesY(2); // 2x2 texture animation 82 fire.setEndColor(new ColorRGBA(1f, 0f, 0f, 1f)); // red 83 fire.setStartColor(new ColorRGBA(1f, 1f, 0f, 0.5f)); // yellow 84 fire.setStartSize(0.6f); 85 fire.setEndSize(0.01f); 86 fire.setGravity(0, -0.3f, 0); 87 fire.setLowLife(0.5f); 88 fire.setHighLife(3f); 89 fire.setLocalTranslation(0, 0.2f, 0); 90 91 rootNode.attachChild(fire); 92 93 94 ParticleEmitter smoke = new ParticleEmitter("Smoke", ParticleMesh.Type.Triangle, 30); 95 smoke.setMaterial(material); 96 smoke.setShape(new EmitterSphereShape(Vector3f.ZERO, 5)); 97 smoke.setImagesX(1); 98 smoke.setImagesY(1); // 2x2 texture animation 99 smoke.setStartColor(new ColorRGBA(0.1f, 0.1f, 0.1f,1f)); // dark gray 100 smoke.setEndColor(new ColorRGBA(0.5f, 0.5f, 0.5f, 0.3f)); // gray 101 smoke.setStartSize(3f); 102 smoke.setEndSize(5f); 103 smoke.setGravity(0, -0.001f, 0); 104 smoke.setLowLife(100f); 105 smoke.setHighLife(100f); 106 smoke.setLocalTranslation(0, 0.1f, 0); 107 smoke.emitAllParticles(); 108 109 rootNode.attachChild(smoke); 110 111 112 inputManager.addListener(new ActionListener() { 113 114 public void onAction(String name, boolean isPressed, float tpf) { 115 if(isPressed && name.equals("toggle")){ 116 // tbf.setEnabled(!tbf.isEnabled()); 117 softParticles = !softParticles; 118 if(softParticles){ 119 viewPort.addProcessor(fpp); 120 }else{ 121 viewPort.removeProcessor(fpp); 122 } 123 } 124 } 125 }, "toggle"); 126 inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE)); 127 } 128 129 130} 131