|
|
|
@ -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,13 +97,48 @@ public class TestSoftParticles extends SimpleApplication { |
|
|
|
|
fpp.addFilter(tbf); |
|
|
|
|
viewPort.addProcessor(fpp); |
|
|
|
|
|
|
|
|
|
particleNode = new Node("particleNode"); |
|
|
|
|
rootNode.attachChild(particleNode); |
|
|
|
|
|
|
|
|
|
createParticles(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inputManager.addListener(new ActionListener() { |
|
|
|
|
|
|
|
|
|
public void onAction(String name, boolean isPressed, float tpf) { |
|
|
|
|
if(isPressed && name.equals("toggle")){ |
|
|
|
|
// tbf.setEnabled(!tbf.isEnabled());
|
|
|
|
|
softParticles = !softParticles; |
|
|
|
|
if(softParticles){ |
|
|
|
|
viewPort.addProcessor(fpp); |
|
|
|
|
}else{ |
|
|
|
|
viewPort.removeProcessor(fpp); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, "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); |
|
|
|
@ -115,7 +154,7 @@ public class TestSoftParticles extends SimpleApplication { |
|
|
|
|
fire.setHighLife(3f); |
|
|
|
|
fire.setLocalTranslation(0, 0.2f, 0); |
|
|
|
|
|
|
|
|
|
rootNode.attachChild(fire); |
|
|
|
|
particleNode.attachChild(fire); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParticleEmitter smoke = new ParticleEmitter("Smoke", ParticleMesh.Type.Triangle, 30); |
|
|
|
@ -133,24 +172,7 @@ public class TestSoftParticles extends SimpleApplication { |
|
|
|
|
smoke.setLocalTranslation(0, 0.1f, 0); |
|
|
|
|
smoke.emitAllParticles(); |
|
|
|
|
|
|
|
|
|
rootNode.attachChild(smoke); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inputManager.addListener(new ActionListener() { |
|
|
|
|
|
|
|
|
|
public void onAction(String name, boolean isPressed, float tpf) { |
|
|
|
|
if(isPressed && name.equals("toggle")){ |
|
|
|
|
// tbf.setEnabled(!tbf.isEnabled());
|
|
|
|
|
softParticles = !softParticles; |
|
|
|
|
if(softParticles){ |
|
|
|
|
viewPort.addProcessor(fpp); |
|
|
|
|
}else{ |
|
|
|
|
viewPort.removeProcessor(fpp); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, "toggle"); |
|
|
|
|
inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE)); |
|
|
|
|
particleNode.attachChild(smoke); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|