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
This commit is contained in:
parent
6c4a84fa92
commit
8f59984d00
@ -75,7 +75,6 @@ public class ParticleEmitter extends Geometry {
|
|||||||
|
|
||||||
private static final EmitterShape DEFAULT_SHAPE = new EmitterPointShape(Vector3f.ZERO);
|
private static final EmitterShape DEFAULT_SHAPE = new EmitterPointShape(Vector3f.ZERO);
|
||||||
private static final ParticleInfluencer DEFAULT_INFLUENCER = new DefaultParticleInfluencer();
|
private static final ParticleInfluencer DEFAULT_INFLUENCER = new DefaultParticleInfluencer();
|
||||||
|
|
||||||
private ParticleEmitterControl control;
|
private ParticleEmitterControl control;
|
||||||
private EmitterShape shape = DEFAULT_SHAPE;
|
private EmitterShape shape = DEFAULT_SHAPE;
|
||||||
private ParticleMesh particleMesh;
|
private ParticleMesh particleMesh;
|
||||||
@ -201,7 +200,7 @@ public class ParticleEmitter extends Geometry {
|
|||||||
|
|
||||||
meshType = type;
|
meshType = type;
|
||||||
|
|
||||||
this.setNumParticles(numParticles);
|
|
||||||
|
|
||||||
// Must create clone of shape/influencer so that a reference to a static is
|
// Must create clone of shape/influencer so that a reference to a static is
|
||||||
// not maintained
|
// not maintained
|
||||||
@ -223,7 +222,8 @@ public class ParticleEmitter extends Geometry {
|
|||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unrecognized particle type: " + meshType);
|
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++) {
|
for (int i = 0; i < numParticles; i++) {
|
||||||
particles[i] = new Particle();
|
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;
|
firstUnUsed = 0;
|
||||||
lastUsed = -1;
|
lastUsed = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMaxNumParticles() {
|
||||||
|
return particles.length;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of all particles (shouldn't be used in most cases).
|
* 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);
|
FloatBuffer pb = BufferUtils.createVector3Buffer(numParticles);
|
||||||
VertexBuffer pvb = new VertexBuffer(VertexBuffer.Type.Position);
|
VertexBuffer pvb = new VertexBuffer(VertexBuffer.Type.Position);
|
||||||
pvb.setupData(Usage.Stream, 3, Format.Float, pb);
|
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);
|
setBuffer(pvb);
|
||||||
|
}
|
||||||
|
|
||||||
// set colors
|
// set colors
|
||||||
ByteBuffer cb = BufferUtils.createByteBuffer(numParticles * 4);
|
ByteBuffer cb = BufferUtils.createByteBuffer(numParticles * 4);
|
||||||
VertexBuffer cvb = new VertexBuffer(VertexBuffer.Type.Color);
|
VertexBuffer cvb = new VertexBuffer(VertexBuffer.Type.Color);
|
||||||
cvb.setupData(Usage.Stream, 4, Format.UnsignedByte, cb);
|
cvb.setupData(Usage.Stream, 4, Format.UnsignedByte, cb);
|
||||||
cvb.setNormalized(true);
|
cvb.setNormalized(true);
|
||||||
|
|
||||||
|
buf = getBuffer(VertexBuffer.Type.Color);
|
||||||
|
if (buf != null) {
|
||||||
|
buf.updateData(cb);
|
||||||
|
} else {
|
||||||
setBuffer(cvb);
|
setBuffer(cvb);
|
||||||
|
}
|
||||||
|
|
||||||
// set sizes
|
// set sizes
|
||||||
FloatBuffer sb = BufferUtils.createFloatBuffer(numParticles);
|
FloatBuffer sb = BufferUtils.createFloatBuffer(numParticles);
|
||||||
VertexBuffer svb = new VertexBuffer(VertexBuffer.Type.Size);
|
VertexBuffer svb = new VertexBuffer(VertexBuffer.Type.Size);
|
||||||
svb.setupData(Usage.Stream, 1, Format.Float, sb);
|
svb.setupData(Usage.Stream, 1, Format.Float, sb);
|
||||||
|
|
||||||
|
buf = getBuffer(VertexBuffer.Type.Size);
|
||||||
|
if (buf != null) {
|
||||||
|
buf.updateData(sb);
|
||||||
|
} else {
|
||||||
setBuffer(svb);
|
setBuffer(svb);
|
||||||
|
}
|
||||||
|
|
||||||
// set UV-scale
|
// set UV-scale
|
||||||
FloatBuffer tb = BufferUtils.createFloatBuffer(numParticles*4);
|
FloatBuffer tb = BufferUtils.createFloatBuffer(numParticles*4);
|
||||||
VertexBuffer tvb = new VertexBuffer(VertexBuffer.Type.TexCoord);
|
VertexBuffer tvb = new VertexBuffer(VertexBuffer.Type.TexCoord);
|
||||||
tvb.setupData(Usage.Stream, 4, Format.Float, tb);
|
tvb.setupData(Usage.Stream, 4, Format.Float, tb);
|
||||||
|
|
||||||
|
buf = getBuffer(VertexBuffer.Type.TexCoord);
|
||||||
|
if (buf != null) {
|
||||||
|
buf.updateData(tb);
|
||||||
|
} else {
|
||||||
setBuffer(tvb);
|
setBuffer(tvb);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateParticleData(Particle[] particles, Camera cam, Matrix3f inverseRotation) {
|
public void updateParticleData(Particle[] particles, Camera cam, Matrix3f inverseRotation) {
|
||||||
|
@ -66,14 +66,27 @@ public class ParticleTriMesh extends ParticleMesh {
|
|||||||
FloatBuffer pb = BufferUtils.createVector3Buffer(numParticles * 4);
|
FloatBuffer pb = BufferUtils.createVector3Buffer(numParticles * 4);
|
||||||
VertexBuffer pvb = new VertexBuffer(VertexBuffer.Type.Position);
|
VertexBuffer pvb = new VertexBuffer(VertexBuffer.Type.Position);
|
||||||
pvb.setupData(Usage.Stream, 3, Format.Float, pb);
|
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);
|
setBuffer(pvb);
|
||||||
|
}
|
||||||
|
|
||||||
// set colors
|
// set colors
|
||||||
ByteBuffer cb = BufferUtils.createByteBuffer(numParticles * 4 * 4);
|
ByteBuffer cb = BufferUtils.createByteBuffer(numParticles * 4 * 4);
|
||||||
VertexBuffer cvb = new VertexBuffer(VertexBuffer.Type.Color);
|
VertexBuffer cvb = new VertexBuffer(VertexBuffer.Type.Color);
|
||||||
cvb.setupData(Usage.Stream, 4, Format.UnsignedByte, cb);
|
cvb.setupData(Usage.Stream, 4, Format.UnsignedByte, cb);
|
||||||
cvb.setNormalized(true);
|
cvb.setNormalized(true);
|
||||||
|
|
||||||
|
buf = getBuffer(VertexBuffer.Type.Color);
|
||||||
|
if (buf != null) {
|
||||||
|
buf.updateData(cb);
|
||||||
|
} else {
|
||||||
setBuffer(cvb);
|
setBuffer(cvb);
|
||||||
|
}
|
||||||
|
|
||||||
// set texcoords
|
// set texcoords
|
||||||
VertexBuffer tvb = new VertexBuffer(VertexBuffer.Type.TexCoord);
|
VertexBuffer tvb = new VertexBuffer(VertexBuffer.Type.TexCoord);
|
||||||
@ -89,7 +102,12 @@ public class ParticleTriMesh extends ParticleMesh {
|
|||||||
tb.flip();
|
tb.flip();
|
||||||
tvb.setupData(Usage.Static, 2, Format.Float, tb);
|
tvb.setupData(Usage.Static, 2, Format.Float, tb);
|
||||||
|
|
||||||
|
buf = getBuffer(VertexBuffer.Type.TexCoord);
|
||||||
|
if (buf != null) {
|
||||||
|
buf.updateData(tb);
|
||||||
|
} else {
|
||||||
setBuffer(tvb);
|
setBuffer(tvb);
|
||||||
|
}
|
||||||
|
|
||||||
// set indices
|
// set indices
|
||||||
ShortBuffer ib = BufferUtils.createShortBuffer(numParticles * 6);
|
ShortBuffer ib = BufferUtils.createShortBuffer(numParticles * 6);
|
||||||
@ -110,9 +128,16 @@ public class ParticleTriMesh extends ParticleMesh {
|
|||||||
|
|
||||||
VertexBuffer ivb = new VertexBuffer(VertexBuffer.Type.Index);
|
VertexBuffer ivb = new VertexBuffer(VertexBuffer.Type.Index);
|
||||||
ivb.setupData(Usage.Static, 3, Format.UnsignedShort, ib);
|
ivb.setupData(Usage.Static, 3, Format.UnsignedShort, ib);
|
||||||
|
|
||||||
|
buf = getBuffer(VertexBuffer.Type.Index);
|
||||||
|
if (buf != null) {
|
||||||
|
buf.updateData(ib);
|
||||||
|
} else {
|
||||||
setBuffer(ivb);
|
setBuffer(ivb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setImagesXY(int imagesX, int imagesY) {
|
public void setImagesXY(int imagesX, int imagesY) {
|
||||||
this.imagesX = imagesX;
|
this.imagesX = imagesX;
|
||||||
|
@ -29,13 +29,16 @@
|
|||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package jme3test.effect;
|
package jme3test.effect;
|
||||||
|
|
||||||
import com.jme3.app.SimpleApplication;
|
import com.jme3.app.SimpleApplication;
|
||||||
import com.jme3.effect.ParticleEmitter;
|
import com.jme3.effect.ParticleEmitter;
|
||||||
import com.jme3.effect.ParticleMesh.Type;
|
import com.jme3.effect.ParticleMesh.Type;
|
||||||
import com.jme3.effect.shapes.EmitterSphereShape;
|
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.material.Material;
|
||||||
import com.jme3.math.FastMath;
|
import com.jme3.math.FastMath;
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
@ -57,7 +60,7 @@ public class TestMovingParticle extends SimpleApplication {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
emit = new ParticleEmitter("Emitter", Type.Triangle, 200);
|
emit = new ParticleEmitter("Emitter", Type.Triangle, 300);
|
||||||
emit.setGravity(0, 0, 0);
|
emit.setGravity(0, 0, 0);
|
||||||
emit.setVelocityVariation(1);
|
emit.setVelocityVariation(1);
|
||||||
emit.setLowLife(1);
|
emit.setLowLife(1);
|
||||||
@ -69,6 +72,17 @@ public class TestMovingParticle extends SimpleApplication {
|
|||||||
emit.setMaterial(mat);
|
emit.setMaterial(mat);
|
||||||
|
|
||||||
rootNode.attachChild(emit);
|
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
|
@Override
|
||||||
@ -79,5 +93,4 @@ public class TestMovingParticle extends SimpleApplication {
|
|||||||
float y = FastMath.sin(angle) * 2;
|
float y = FastMath.sin(angle) * 2;
|
||||||
emit.setLocalTranslation(x, 0, y);
|
emit.setLocalTranslation(x, 0, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,9 @@ import com.jme3.app.SimpleApplication;
|
|||||||
import com.jme3.effect.ParticleEmitter;
|
import com.jme3.effect.ParticleEmitter;
|
||||||
import com.jme3.effect.ParticleMesh.Type;
|
import com.jme3.effect.ParticleMesh.Type;
|
||||||
import com.jme3.effect.shapes.EmitterBoxShape;
|
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.material.Material;
|
||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
@ -49,13 +52,13 @@ public class TestPointSprite extends SimpleApplication {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleInitApp() {
|
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),
|
emit.setShape(new EmitterBoxShape(new Vector3f(-1.8f, -1.8f, -1.8f),
|
||||||
new Vector3f(1.8f, 1.8f, 1.8f)));
|
new Vector3f(1.8f, 1.8f, 1.8f)));
|
||||||
emit.setGravity(0, 0, 0);
|
emit.setGravity(0, 0, 0);
|
||||||
emit.setLowLife(60);
|
emit.setLowLife(60);
|
||||||
emit.setHighLife(60);
|
emit.setHighLife(60);
|
||||||
emit.setInitialVelocity(new Vector3f(0, 0, 0));
|
emit.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 0, 0));
|
||||||
emit.setImagesX(15);
|
emit.setImagesX(15);
|
||||||
emit.setStartSize(0.05f);
|
emit.setStartSize(0.05f);
|
||||||
emit.setEndSize(0.05f);
|
emit.setEndSize(0.05f);
|
||||||
@ -70,6 +73,17 @@ public class TestPointSprite extends SimpleApplication {
|
|||||||
emit.setMaterial(mat);
|
emit.setMaterial(mat);
|
||||||
|
|
||||||
rootNode.attachChild(emit);
|
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…
x
Reference in New Issue
Block a user