Particle Emitter :

- fixed setNumParticle method to correctly update the mesh buffers
- added a getMaxNumParticle that returns the max number of particles of the emitter
- changed testMovingParticles and testPointSprite to change the numParticle when hitting the space bar

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7939 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 14 years ago
parent 6c4a84fa92
commit 8f59984d00
  1. 13
      engine/src/core/com/jme3/effect/ParticleEmitter.java
  2. 25
      engine/src/core/com/jme3/effect/ParticlePointMesh.java
  3. 25
      engine/src/core/com/jme3/effect/ParticleTriMesh.java
  4. 19
      engine/src/test/jme3test/effect/TestMovingParticle.java
  5. 18
      engine/src/test/jme3test/effect/TestPointSprite.java

@ -75,7 +75,6 @@ public class ParticleEmitter extends Geometry {
private static final EmitterShape DEFAULT_SHAPE = new EmitterPointShape(Vector3f.ZERO);
private static final ParticleInfluencer DEFAULT_INFLUENCER = new DefaultParticleInfluencer();
private ParticleEmitterControl control;
private EmitterShape shape = DEFAULT_SHAPE;
private ParticleMesh particleMesh;
@ -201,7 +200,7 @@ public class ParticleEmitter extends Geometry {
meshType = type;
this.setNumParticles(numParticles);
// Must create clone of shape/influencer so that a reference to a static is
// not maintained
@ -223,7 +222,8 @@ public class ParticleEmitter extends Geometry {
default:
throw new IllegalStateException("Unrecognized particle type: " + meshType);
}
particleMesh.initParticleData(this, particles.length);
this.setNumParticles(numParticles);
// particleMesh.initParticleData(this, particles.length);
}
/**
@ -330,10 +330,17 @@ public class ParticleEmitter extends Geometry {
for (int i = 0; i < numParticles; i++) {
particles[i] = new Particle();
}
//We have to reinit the mesh's buffers with the new size
particleMesh.initParticleData(this, particles.length);
particleMesh.setImagesXY(this.imagesX, this.imagesY);
firstUnUsed = 0;
lastUsed = -1;
}
public int getMaxNumParticles() {
return particles.length;
}
/**
* Returns a list of all particles (shouldn't be used in most cases).
*

@ -64,27 +64,52 @@ public class ParticlePointMesh extends ParticleMesh {
FloatBuffer pb = BufferUtils.createVector3Buffer(numParticles);
VertexBuffer pvb = new VertexBuffer(VertexBuffer.Type.Position);
pvb.setupData(Usage.Stream, 3, Format.Float, pb);
//if the buffer is already set only update the data
VertexBuffer buf = getBuffer(VertexBuffer.Type.Position);
if (buf != null) {
buf.updateData(pb);
} else {
setBuffer(pvb);
}
// set colors
ByteBuffer cb = BufferUtils.createByteBuffer(numParticles * 4);
VertexBuffer cvb = new VertexBuffer(VertexBuffer.Type.Color);
cvb.setupData(Usage.Stream, 4, Format.UnsignedByte, cb);
cvb.setNormalized(true);
buf = getBuffer(VertexBuffer.Type.Color);
if (buf != null) {
buf.updateData(cb);
} else {
setBuffer(cvb);
}
// set sizes
FloatBuffer sb = BufferUtils.createFloatBuffer(numParticles);
VertexBuffer svb = new VertexBuffer(VertexBuffer.Type.Size);
svb.setupData(Usage.Stream, 1, Format.Float, sb);
buf = getBuffer(VertexBuffer.Type.Size);
if (buf != null) {
buf.updateData(sb);
} else {
setBuffer(svb);
}
// set UV-scale
FloatBuffer tb = BufferUtils.createFloatBuffer(numParticles*4);
VertexBuffer tvb = new VertexBuffer(VertexBuffer.Type.TexCoord);
tvb.setupData(Usage.Stream, 4, Format.Float, tb);
buf = getBuffer(VertexBuffer.Type.TexCoord);
if (buf != null) {
buf.updateData(tb);
} else {
setBuffer(tvb);
}
}
@Override
public void updateParticleData(Particle[] particles, Camera cam, Matrix3f inverseRotation) {

@ -66,14 +66,27 @@ public class ParticleTriMesh extends ParticleMesh {
FloatBuffer pb = BufferUtils.createVector3Buffer(numParticles * 4);
VertexBuffer pvb = new VertexBuffer(VertexBuffer.Type.Position);
pvb.setupData(Usage.Stream, 3, Format.Float, pb);
//if the buffer is already set only update the data
VertexBuffer buf = getBuffer(VertexBuffer.Type.Position);
if (buf != null) {
buf.updateData(pb);
} else {
setBuffer(pvb);
}
// set colors
ByteBuffer cb = BufferUtils.createByteBuffer(numParticles * 4 * 4);
VertexBuffer cvb = new VertexBuffer(VertexBuffer.Type.Color);
cvb.setupData(Usage.Stream, 4, Format.UnsignedByte, cb);
cvb.setNormalized(true);
buf = getBuffer(VertexBuffer.Type.Color);
if (buf != null) {
buf.updateData(cb);
} else {
setBuffer(cvb);
}
// set texcoords
VertexBuffer tvb = new VertexBuffer(VertexBuffer.Type.TexCoord);
@ -89,7 +102,12 @@ public class ParticleTriMesh extends ParticleMesh {
tb.flip();
tvb.setupData(Usage.Static, 2, Format.Float, tb);
buf = getBuffer(VertexBuffer.Type.TexCoord);
if (buf != null) {
buf.updateData(tb);
} else {
setBuffer(tvb);
}
// set indices
ShortBuffer ib = BufferUtils.createShortBuffer(numParticles * 6);
@ -110,9 +128,16 @@ public class ParticleTriMesh extends ParticleMesh {
VertexBuffer ivb = new VertexBuffer(VertexBuffer.Type.Index);
ivb.setupData(Usage.Static, 3, Format.UnsignedShort, ib);
buf = getBuffer(VertexBuffer.Type.Index);
if (buf != null) {
buf.updateData(ib);
} else {
setBuffer(ivb);
}
}
@Override
public void setImagesXY(int imagesX, int imagesY) {
this.imagesX = imagesX;

@ -29,13 +29,16 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package jme3test.effect;
import com.jme3.app.SimpleApplication;
import com.jme3.effect.ParticleEmitter;
import com.jme3.effect.ParticleMesh.Type;
import com.jme3.effect.shapes.EmitterSphereShape;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.InputListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.material.Material;
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
@ -57,7 +60,7 @@ public class TestMovingParticle extends SimpleApplication {
@Override
public void simpleInitApp() {
emit = new ParticleEmitter("Emitter", Type.Triangle, 200);
emit = new ParticleEmitter("Emitter", Type.Triangle, 300);
emit.setGravity(0, 0, 0);
emit.setVelocityVariation(1);
emit.setLowLife(1);
@ -69,6 +72,17 @@ public class TestMovingParticle extends SimpleApplication {
emit.setMaterial(mat);
rootNode.attachChild(emit);
inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
if ("setNum".equals(name) && isPressed) {
emit.setNumParticles(1000);
}
}
}, "setNum");
inputManager.addMapping("setNum", new KeyTrigger(KeyInput.KEY_SPACE));
}
@Override
@ -79,5 +93,4 @@ public class TestMovingParticle extends SimpleApplication {
float y = FastMath.sin(angle) * 2;
emit.setLocalTranslation(x, 0, y);
}
}

@ -36,6 +36,9 @@ import com.jme3.app.SimpleApplication;
import com.jme3.effect.ParticleEmitter;
import com.jme3.effect.ParticleMesh.Type;
import com.jme3.effect.shapes.EmitterBoxShape;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
@ -49,13 +52,13 @@ public class TestPointSprite extends SimpleApplication {
@Override
public void simpleInitApp() {
ParticleEmitter emit = new ParticleEmitter("Emitter", Type.Point, 10000);
final ParticleEmitter emit = new ParticleEmitter("Emitter", Type.Point, 10000);
emit.setShape(new EmitterBoxShape(new Vector3f(-1.8f, -1.8f, -1.8f),
new Vector3f(1.8f, 1.8f, 1.8f)));
emit.setGravity(0, 0, 0);
emit.setLowLife(60);
emit.setHighLife(60);
emit.setInitialVelocity(new Vector3f(0, 0, 0));
emit.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 0, 0));
emit.setImagesX(15);
emit.setStartSize(0.05f);
emit.setEndSize(0.05f);
@ -70,6 +73,17 @@ public class TestPointSprite extends SimpleApplication {
emit.setMaterial(mat);
rootNode.attachChild(emit);
inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
if ("setNum".equals(name) && isPressed) {
emit.setNumParticles(5000);
emit.emitAllParticles();
}
}
}, "setNum");
inputManager.addMapping("setNum", new KeyTrigger(KeyInput.KEY_SPACE));
}

Loading…
Cancel
Save