1 /* 2 * Copyright (c) 2009-2010 jMonkeyEngine 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * * Neither the name of 'jMonkeyEngine' nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 package jme3test.effect; 34 35 import com.jme3.app.SimpleApplication; 36 import com.jme3.effect.ParticleEmitter; 37 import com.jme3.effect.ParticleMesh.Type; 38 import com.jme3.effect.shapes.EmitterBoxShape; 39 import com.jme3.input.KeyInput; 40 import com.jme3.input.controls.ActionListener; 41 import com.jme3.input.controls.KeyTrigger; 42 import com.jme3.material.Material; 43 import com.jme3.math.ColorRGBA; 44 import com.jme3.math.Vector3f; 45 46 public class TestPointSprite extends SimpleApplication { 47 main(String[] args)48 public static void main(String[] args){ 49 TestPointSprite app = new TestPointSprite(); 50 app.start(); 51 } 52 53 @Override simpleInitApp()54 public void simpleInitApp() { 55 final ParticleEmitter emit = new ParticleEmitter("Emitter", Type.Point, 10000); 56 emit.setShape(new EmitterBoxShape(new Vector3f(-1.8f, -1.8f, -1.8f), 57 new Vector3f(1.8f, 1.8f, 1.8f))); 58 emit.setGravity(0, 0, 0); 59 emit.setLowLife(60); 60 emit.setHighLife(60); 61 emit.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 0, 0)); 62 emit.setImagesX(15); 63 emit.setStartSize(0.05f); 64 emit.setEndSize(0.05f); 65 emit.setStartColor(ColorRGBA.White); 66 emit.setEndColor(ColorRGBA.White); 67 emit.setSelectRandomImage(true); 68 emit.emitAllParticles(); 69 70 Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"); 71 mat.setBoolean("PointSprite", true); 72 mat.setTexture("Texture", assetManager.loadTexture("Effects/Smoke/Smoke.png")); 73 emit.setMaterial(mat); 74 75 rootNode.attachChild(emit); 76 inputManager.addListener(new ActionListener() { 77 78 public void onAction(String name, boolean isPressed, float tpf) { 79 if ("setNum".equals(name) && isPressed) { 80 emit.setNumParticles(5000); 81 emit.emitAllParticles(); 82 } 83 } 84 }, "setNum"); 85 86 inputManager.addMapping("setNum", new KeyTrigger(KeyInput.KEY_SPACE)); 87 88 } 89 90 } 91