2 * Copyright (c) 2003-2009 jMonkeyEngine
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
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.
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.
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.
33 package jmetest.effects;
35 import com.jme.app.SimpleGame;
36 import com.jme.bounding.BoundingBox;
37 import com.jme.image.Texture;
38 import com.jme.math.FastMath;
39 import com.jme.math.Vector3f;
40 import com.jme.renderer.ColorRGBA;
41 import com.jme.scene.shape.Sphere;
42 import com.jme.scene.state.BlendState;
43 import com.jme.scene.state.TextureState;
44 import com.jme.util.TextureManager;
45 import com.jmex.effects.particles.ParticleFactory;
46 import com.jmex.effects.particles.ParticleInfluence;
47 import com.jmex.effects.particles.ParticleMesh;
48 import com.jmex.effects.particles.SimpleParticleInfluenceFactory;
51 * This test shows off using an existing mesh as the actual geometry for your
54 * @author Joshua Slack
55 * @version $Id: TestBatchParticles.java,v 1.4 2007/09/21 15:46:34 nca Exp $
57 public class TestBatchParticles extends SimpleGame {
59 private ParticleMesh pMesh;
60 private ParticleInfluence wind;
62 public static void main(String[] args) {
63 TestBatchParticles app = new TestBatchParticles();
64 app.setConfigShowMode(ConfigShowMode.AlwaysShow);
68 protected void simpleUpdate() {
72 protected void simpleInitGame() {
73 display.setTitle("Particle System - Batch Particles");
75 TextureState ts = display.getRenderer().createTextureState();
77 Texture tex = TextureManager.loadTexture(
78 TestBatchParticles.class.getClassLoader().getResource(
79 "jmetest/data/images/Monkey.jpg"),
80 Texture.MinificationFilter.Trilinear,
81 Texture.MagnificationFilter.Bilinear);
84 Sphere sphere = new Sphere("sp", 16, 16, 2);
85 sphere.setModelBound(new BoundingBox());
86 sphere.updateModelBound();
87 sphere.setSolidColor(ColorRGBA.white.clone());
88 sphere.setRenderState(ts);
89 rootNode.attachChild(sphere);
91 pMesh = ParticleFactory.buildMeshParticles("particles", sphere);
92 pMesh.setEmissionDirection(new Vector3f(1, 1, 1));
93 pMesh.setOriginOffset(new Vector3f(0, 0, 0));
94 pMesh.setInitialVelocity(.002f);
95 pMesh.setStartSize(1);
97 pMesh.setMinimumLifeTime(1000f);
98 pMesh.setMaximumLifeTime(3000f);
99 pMesh.setStartColor(new ColorRGBA(1, 1, 1, 1));
100 pMesh.setEndColor(new ColorRGBA(1, 1, 1, 0));
101 pMesh.setMaximumAngle(0f * FastMath.DEG_TO_RAD);
102 pMesh.setParticleSpinSpeed(180 * FastMath.DEG_TO_RAD);
103 wind = SimpleParticleInfluenceFactory.createBasicWind(.008f, new Vector3f(-1, 0, 0), true, true);
104 wind.setEnabled(true);
105 pMesh.addInfluence(wind);
106 pMesh.forceRespawn();
108 BlendState as1 = display.getRenderer().createBlendState();
109 as1.setBlendEnabled(true);
110 as1.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
111 as1.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
112 as1.setEnabled(true);
113 rootNode.setRenderState(as1);
115 pMesh.setRenderState(ts);
117 pMesh.setModelBound(new BoundingBox());
118 pMesh.updateModelBound();
120 rootNode.attachChild(pMesh);