| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]--><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="Asciidoctor 1.5.4"><meta name="keywords" content="documentation, effect"><title>Particle Emmitter Settings</title><link rel="stylesheet" href="./asciidoctor.css">
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
- <link rel="stylesheet" href="./coderay-asciidoctor.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.css"><link rel="stylesheet" href="/home/travis/build/jMonkeyEngine/wiki/build/asciidoc/html5/jme3/advanced/twemoji-awesome.css"></head><body class="article toc2 toc-left"><div id="header"><div id="toolbar"><a href="https://github.com/jMonkeyEngine/wiki/edit/master/src/docs/asciidoc/jme3/advanced/particle_emitters.adoc"><i class="fa fa-pencil-square" aria-hidden="true"></i></a><a href="https://github.com/jMonkeyEngine/wiki/new/master/src/docs/asciidoc/jme3/advanced/"><i class="fa fa-plus-square" aria-hidden="true"></i></a><input dir="auto" style="position: relative; vertical-align: top;" spellcheck="false" autocomplete="off" class="searchbox__input aa-input" id="doc-search" name="search" placeholder="Search in the doc" required="required" type="search"></div><h1>Particle Emmitter Settings</h1><div class="details"><span class="author" id="author"></span><br><span id="revnumber">version ,</span> <span id="revdate">2016/03/17 20:48</span></div><div id="toc" class="toc2"><div id="toctitle">Table of Contents</div><ul class="sectlevel1"><li><a href="#create-an-emitter">Create an Emitter</a></li><li><a href="#configure-parameters">Configure Parameters</a></li><li><a href="#create-an-effect-material">Create an Effect Material</a><ul class="sectlevel2"><li><a href="#default-particle-textures">Default Particle Textures</a></li></ul></li><li><a href="#usage-example">Usage Example</a></li></ul></div></div><div id="content"><div id="preamble"><div class="sectionbody"><div class="paragraph"><p>You cannot create a 3D model for delicate things like fire, smoke, or explosions. Particle Emitters are quite an efficient solution to create these kinds of effects: The emitter renders a series of flat orthogonal images and manipulates them in a way that creates the illusion of a anything from a delicate smoke cloud to individual flames, etc.
- Creating an effect involves some trial and error to get the settings <em>just right</em>, and it’s worth exploring the expressiveness of the options described below.</p></div>
- <div class="admonitionblock tip"><table><tr><td class="icon"><i class="fa icon-tip" title="Tip"></i></td><td class="content"><div class="paragraph"><p>Use the <a href="../../sdk/scene_explorer.html">Scene Explorer</a> in the <a href="../../sdk.html">SDK</a> to design and preview effects.</p></div></td></tr></table></div>
- <div class="paragraph"><p><span class="image"><img src="../../jme3/advanced/explosion-5.png" alt="explosion-5.png" width="150" height="100"></span> <span class="image"><img src="../../jme3/advanced/particle.png" alt="particle.png" width="150" height="100"></span> <span class="image"><img src="../../jme3/beginner/beginner-effect-fire.png" alt="beginner-effect-fire.png" width="150" height="100"></span> <span class="image"><img src="../../jme3/advanced/butterfly-particle-emitter.png" alt="butterfly-particle-emitter.png" width="150" height="100"></span></p></div></div></div>
- <div class="sect1"><h2 id="create-an-emitter">Create an Emitter</h2><div class="sectionbody"><div class="olist arabic"><ol class="arabic"><li><p>Create one emitter for each effect:</p><div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">ParticleEmitter explosion = <span class="keyword">new</span> ParticleEmitter(
- <span class="string"><span class="delimiter">"</span><span class="content">My explosion effect</span><span class="delimiter">"</span></span>, <span class="predefined-type">Type</span>.Triangle, <span class="integer">30</span>);</code></pre></div></div></li><li><p>Attach the emitter to the rootNode and position it in the scene:</p><div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">rootNode.attachChild(explosion);
- explosion.setLocalTranslation(bomb.getLocalTranslation());</code></pre></div></div></li><li><p>Trigger the effect by calling</p><div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">explosion.emitAllParticles()</code></pre></div></div></li><li><p>End the effect by calling</p><div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">explosion.killAllParticles()</code></pre></div></div></li></ol></div>
- <div class="paragraph"><p>Choose one of the following mesh shapes</p></div>
- <div class="ulist"><ul><li><p>Type.Triangle</p></li><li><p>Type.Point</p></li></ul></div></div></div>
- <div class="sect1"><h2 id="configure-parameters">Configure Parameters</h2><div class="sectionbody"><div class="paragraph"><p>Not all of these parameters are required for all kinds of effects. If you don’t specify one of them, a default value will be used.</p></div>
- <table class="tableblock frame-all grid-all spread"><colgroup><col style="width: 15%;"><col style="width: 25%;"><col style="width: 20%;"><col style="width: 40%;"></colgroup><thead><tr><th class="tableblock halign-left valign-top">Parameter</th><th class="tableblock halign-left valign-top">Method</th><th class="tableblock halign-left valign-top">Default</th><th class="tableblock halign-left valign-top">Description</th></tr></thead><tbody><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>number</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><code>setNumParticles()</code></p></div></div></td><td class="tableblock halign-left valign-top"><div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>The maximum number of particles visible at the same time. Specified by user in constructor.</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>emission rate</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><code>setParticlesPerSec()</code></p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>20</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Density of the effect, how many new particles are emitted per second.<br>
- Set to zero to control the start/end of the effect.<br>
- Set to a number for a constantly running effect.</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>size</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><code>setStartSize()</code>, <code>setEndSize()</code></p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>0.2f, 2f</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>The radius of the scaled sprite image. Set both to same value for constant size effect.<br>
- Set to different values for shrink/grow effect.</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>color</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><code>setStartColor()</code>, <code>setEndColor()</code></p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>gray</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Controls how the opaque (non-black) parts of the texture are colorized.<br>
- Set both to the same color for single-colored effects (e.g. fog, debris).<br>
- Set both to different colors for a gradient effect (e.g. fire).</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>direction/velocity</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><code>getParticleInfluencer(). setInitialVelocity(initialVelocity)</code></p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Vector3f(0,0,0)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>A vector specifying the initial direction and speed of particles. The longer the vector, the faster.</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>fanning out</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><code>getParticleInfluencer().setVelocityVariation(variation)</code></p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>0.2f</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>How much the direction (<code>setInitialVelocity()</code>) can vary among particles. Use a value between 1 and 0 to create a directed swarm-like cloud of particles.<br>
- 1 = Maximum variation, particles emit in random 360° directions (e.g. explosion, butterflies).<br>
- 0.5f = particles are emitted within 180° of the initial direction.<br>
- 0 = No variation, particles fly in a straight line in direction of start velocity (e.g. lasergun blasts).</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>direction<br>
- (pick one)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><code>setFacingVelocity()</code></p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>false</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>true = Flying particles pitch in the direction they’re flying (e.g. missiles).<br>
- false = Particles keep flying rotated the way they started (e.g. debris).</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>direction<br>
- (pick one)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><code>setFaceNormal()</code></p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Vector3f.NAN</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Vector3f = Flying particles face in the given direction (e.g. horizontal shockwave faces up = Vector3f.UNIT_Y).<br>
- Vector3f.NAN = Flying particles face the camera.</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>lifetime</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><code>setLowLife()</code>, <code>setHighLife()</code></p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>3f, 7f</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>The time period before a particle fades is set to a random value between minimum and maximum; minimum must be smaller than maximum. A minimum < 1f makes the effect more busy, a higher minimum looks more steady. Use a maximum < 1f for short bursts, and higher maxima for long lasting swarms or smoke. Set maximum and minimum to similar values to create an evenly spaced effect (e.g. fountain), set the to very different values to create a distorted effect (e.g. fire with individual long flames).</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>spinning</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><code>setRotateSpeed()</code></p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>0f</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>0 = Flying particles don’t spin while flying (e.g. smoke, insects, controlled projectiles).<br>
- > 0 = How fast particle spins while flying (e.g. debris, shuriken, missiles out of control).</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>rotation</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><code>setRandomAngle()</code></p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>false</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>true = The particle sprite is rotated at a random angle when it is emitted (e.g. explosion, debris).<br>
- false = Particles fly straight like you drew them in the sprite texture (e.g. insects).</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>gravity</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><code>setGravity()</code></p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Vector3f(0.0f,0.1f,0.0f)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Particles fall in the direction of the vector (e.g. debris, sparks).<br>
- (0,0,0) = Particles keep flying in start direction (e.g. flames, zero-gravity explosion.)</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>start area</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><code>setShape(new EmitterSphereShape( Vector3f.ZERO, 2f));</code></p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>EmitterPointShape()</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>By default, particles are emitted from the emitters location (a point). You can increase the emitter shape to occupy a sphere, so that the start point of new particles can be anywhere inside the sphere, which makes the effect a bit more irregular.</p></div></div></td></tr></tbody></table>
- <div class="paragraph"><p>Build up your effect by specifying one parameter after the other. If you change several parameters at the same time, it’s difficult to tell which of the values caused which outcome.</p></div></div></div>
- <div class="sect2"><h3 id="create-an-effect-material">Create an Effect Material</h3><div style="text-align: right;" class="imageblock"><div class="content"><img src="../../jme3/beginner/flash.png" alt="flash.png" width="128" height="128"></div></div>
- <div class="paragraph"><p>Use the common Particle.j3md Material Definition and a texture to specify the shape of the particles. The shape is defined by the texture you provide and can be anything – debris, flames, smoke, mosquitoes, leaves, butterflies… be creative.</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java"> Material flash_mat = <span class="keyword">new</span> Material(
- assetManager, <span class="string"><span class="delimiter">"</span><span class="content">Common/MatDefs/Misc/Particle.j3md</span><span class="delimiter">"</span></span>);
- flash_mat.setTexture(<span class="string"><span class="delimiter">"</span><span class="content">Texture</span><span class="delimiter">"</span></span>,
- assetManager.loadTexture(<span class="string"><span class="delimiter">"</span><span class="content">Effects/Explosion/flash.png</span><span class="delimiter">"</span></span>));
- flash.setMaterial(flash_mat);
- flash.setImagesX(<span class="integer">2</span>); <span class="comment">// columns</span>
- flash.setImagesY(<span class="integer">2</span>); <span class="comment">// rows</span>
- flash.setSelectRandomImage(<span class="predefined-constant">true</span>);</code></pre></div></div>
- <div class="paragraph"><p>The effect texture can be one image, or contain a sprite animation – a series of slightly different pictures in equally spaced rows and columns. If you choose the sprite animation:</p></div>
- <div class="ulist"><ul><li><p>Specify the number of rows and columns using setImagesX(2) and setImagesY().</p></li><li><p>Specify whether you want to play the sprite series in order (animation), or at random (explosion, flame), by setting setSelectRandomImage() true or false.</p></li></ul></div>
- <div class="paragraph"><p><strong>Examples:</strong> Have a look at the following default textures and you will see how you can create your own sprite textures after the same fashion.</p></div>
- <div class="sect2"><h3 id="default-particle-textures">Default Particle Textures</h3><div class="paragraph"><p>The Material is used together with grayscale texture: The black parts will be transparent and the white parts will be opaque (colored).
- The following effect textures are available by default from <code>test-data.jar</code>. You can also load your own textures from your assets directory.</p></div>
- <table class="tableblock frame-all grid-all spread"><colgroup><col style="width: 33.3333%;"><col style="width: 33.3333%;"><col style="width: 33.3334%;"></colgroup><thead><tr><th class="tableblock halign-left valign-top">Texture Path</th><th class="tableblock halign-left valign-top">Dimension</th><th class="tableblock halign-left valign-top">Preview</th></tr></thead><tbody><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Effects/Explosion/Debris.png</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>3*3</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><span class="image"><img src="../../jme3/beginner/Debris.png" alt="Debris.png" width="32" height="32"></span></p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Effects/Explosion/flame.png</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>2*2</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><span class="image"><img src="../../jme3/beginner/flame.png" alt="flame.png" width="32" height="32"></span></p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Effects/Explosion/flash.png</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>2*2</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><span class="image"><img src="../../jme3/beginner/flash.png" alt="flash.png" width="32" height="32"></span></p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Effects/Explosion/roundspark.png</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>1*1</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><span class="image"><img src="../../jme3/beginner/roundspark.png" alt="roundspark.png" width="32" height="32"></span></p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Effects/Explosion/shockwave.png</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>1*1</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><span class="image"><img src="../../jme3/beginner/shockwave.png" alt="shockwave.png" width="32" height="32"></span></p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Effects/Explosion/smoketrail.png</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>1*3</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><span class="image"><img src="../../jme3/beginner/smoketrail.png" alt="smoketrail.png" width="32" height="32"></span></p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Effects/Explosion/spark.png</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>1*1</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><span class="image"><img src="../../jme3/beginner/spark.png" alt="spark.png" width="32" height="32"></span></p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Effects/Smoke/Smoke.png</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>1*15</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><span class="image"><img src="../../jme3/beginner/Smoke.png" alt="Smoke.png" width="96" height="32"></span></p></div></div></td></tr></tbody></table>
- <div class="admonitionblock tip"><table><tr><td class="icon"><i class="fa icon-tip" title="Tip"></i></td><td class="content"><div class="paragraph"><p>Use the <code>setStartColor()</code>/<code>setEndColor()</code> settings described above to colorize the white and gray parts of textures.</p></div></td></tr></table></div></div></div>
- <div class="sect1"><h2 id="usage-example">Usage Example</h2><div class="sectionbody"><div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java"> ParticleEmitter fire = <span class="keyword">new</span> ParticleEmitter(<span class="string"><span class="delimiter">"</span><span class="content">Emitter</span><span class="delimiter">"</span></span>, <span class="predefined-type">Type</span>.Triangle, <span class="integer">30</span>);
- Material mat_red = <span class="keyword">new</span> Material(assetManager, <span class="string"><span class="delimiter">"</span><span class="content">Common/MatDefs/Misc/Particle.j3md</span><span class="delimiter">"</span></span>);
- mat_red.setTexture(<span class="string"><span class="delimiter">"</span><span class="content">Texture</span><span class="delimiter">"</span></span>, assetManager.loadTexture(<span class="string"><span class="delimiter">"</span><span class="content">Effects/Explosion/flame.png</span><span class="delimiter">"</span></span>));
- fire.setMaterial(mat_red);
- fire.setImagesX(<span class="integer">2</span>); fire.setImagesY(<span class="integer">2</span>); <span class="comment">// 2x2 texture animation</span>
- fire.setEndColor( <span class="keyword">new</span> ColorRGBA(<span class="float">1f</span>, <span class="float">0f</span>, <span class="float">0f</span>, <span class="float">1f</span>)); <span class="comment">// red</span>
- fire.setStartColor(<span class="keyword">new</span> ColorRGBA(<span class="float">1f</span>, <span class="float">1f</span>, <span class="float">0f</span>, <span class="float">0.5f</span>)); <span class="comment">// yellow</span>
- fire.getParticleInfluencer().setInitialVelocity(<span class="keyword">new</span> Vector3f(<span class="integer">0</span>,<span class="integer">2</span>,<span class="integer">0</span>));
- fire.setStartSize(<span class="float">1.5f</span>);
- fire.setEndSize(<span class="float">0.1f</span>);
- fire.setGravity(<span class="integer">0</span>,<span class="integer">0</span>,<span class="integer">0</span>);
- fire.setLowLife(<span class="float">0.5f</span>);
- fire.setHighLife(<span class="float">3f</span>);
- fire.getParticleInfluencer().setVelocityVariation(<span class="float">0.3f</span>);
- rootNode.attachChild(fire);</code></pre></div></div>
- <div class="paragraph"><p>Browse the full source code of all <a href="https://github.com/jMonkeyEngine/jmonkeyengine/tree/master/jme3-examples/src/main/java/jme3test/effect">effect examples</a> here.</p></div>
- <hr>
- <div class="paragraph"><p>See also: <a href="../../jme3/advanced/effects_overview.html">Effects Overview</a></p></div></div></div></div><div id="footer"><div id="footer-text">Version <br>Last updated 2019-12-20 23:30:51 +00:00</div></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js"></script><script>docsearch({
- apiKey: 'a736b6d93de805e26ec2f49b55013fbd',
- indexName: 'jmonkeyengine',
- inputSelector: '#doc-search',
- debug: false // Set debug to true if you want to inspect the dropdown
- });</script></body></html>
|