OSDN Git Service

5224bae88970f6b7cf5931c1de2f398a3fd243b8
[mikumikustudio/MikuMikuStudio.git] / src / jmetest / effects / TestBatchParticles.java
1 /*
2  * Copyright (c) 2003-2009 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 jmetest.effects;
34
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;
49
50 /**
51  * This test shows off using an existing mesh as the actual geometry for your
52  * particle system.
53  * 
54  * @author Joshua Slack
55  * @version $Id: TestBatchParticles.java,v 1.4 2007/09/21 15:46:34 nca Exp $
56  */
57 public class TestBatchParticles extends SimpleGame {
58
59     private ParticleMesh pMesh;
60     private ParticleInfluence wind;
61
62     public static void main(String[] args) {
63         TestBatchParticles app = new TestBatchParticles();
64         app.setConfigShowMode(ConfigShowMode.AlwaysShow);
65         app.start();
66     }
67
68     protected void simpleUpdate() {
69
70     }
71
72     protected void simpleInitGame() {
73         display.setTitle("Particle System - Batch Particles");
74         
75         TextureState ts = display.getRenderer().createTextureState();
76         ts.setEnabled(true);
77         Texture tex = TextureManager.loadTexture(
78             TestBatchParticles.class.getClassLoader().getResource(
79             "jmetest/data/images/Monkey.jpg"),
80             Texture.MinificationFilter.Trilinear,
81             Texture.MagnificationFilter.Bilinear);
82         ts.setTexture(tex);
83
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);
90         
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);
96         pMesh.setEndSize(1f);
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();
107
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);
114         
115         pMesh.setRenderState(ts);
116
117         pMesh.setModelBound(new BoundingBox());
118         pMesh.updateModelBound();
119
120         rootNode.attachChild(pMesh);
121     }
122 }