use of com.jme3.effect.ParticleEmitter in project jmonkeyengine by jMonkeyEngine.
the class TestSoftParticles method createParticles.
private void createParticles() {
Material material = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
material.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
//
material.setFloat("Softness", 3f);
//Fire
ParticleEmitter fire = new ParticleEmitter("Fire", ParticleMesh.Type.Triangle, 30);
fire.setMaterial(material);
fire.setShape(new EmitterSphereShape(Vector3f.ZERO, 0.1f));
fire.setImagesX(2);
// 2x2 texture animation
fire.setImagesY(2);
// red
fire.setEndColor(new ColorRGBA(1f, 0f, 0f, 1f));
// yellow
fire.setStartColor(new ColorRGBA(1f, 1f, 0f, 0.5f));
fire.setStartSize(0.6f);
fire.setEndSize(0.01f);
fire.setGravity(0, -0.3f, 0);
fire.setLowLife(0.5f);
fire.setHighLife(3f);
fire.setLocalTranslation(0, 0.2f, 0);
particleNode.attachChild(fire);
ParticleEmitter smoke = new ParticleEmitter("Smoke", ParticleMesh.Type.Triangle, 30);
smoke.setMaterial(material);
smoke.setShape(new EmitterSphereShape(Vector3f.ZERO, 5));
smoke.setImagesX(1);
// 2x2 texture animation
smoke.setImagesY(1);
// dark gray
smoke.setStartColor(new ColorRGBA(0.1f, 0.1f, 0.1f, 1f));
// gray
smoke.setEndColor(new ColorRGBA(0.5f, 0.5f, 0.5f, 0.3f));
smoke.setStartSize(3f);
smoke.setEndSize(5f);
smoke.setGravity(0, -0.001f, 0);
smoke.setLowLife(100f);
smoke.setHighLife(100f);
smoke.setLocalTranslation(0, 0.1f, 0);
smoke.emitAllParticles();
particleNode.attachChild(smoke);
}
use of com.jme3.effect.ParticleEmitter in project jmonkeyengine by jMonkeyEngine.
the class BombControl method prepareEffect.
private void prepareEffect(AssetManager assetManager) {
int COUNT_FACTOR = 1;
float COUNT_FACTOR_F = 1f;
effect = new ParticleEmitter("Flame", Type.Triangle, 32 * COUNT_FACTOR);
effect.setSelectRandomImage(true);
effect.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, (float) (1f / COUNT_FACTOR_F)));
effect.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f));
effect.setStartSize(1.3f);
effect.setEndSize(2f);
effect.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
effect.setParticlesPerSec(0);
effect.setGravity(0, -5f, 0);
effect.setLowLife(.4f);
effect.setHighLife(.5f);
effect.setInitialVelocity(new Vector3f(0, 7, 0));
effect.setVelocityVariation(1f);
effect.setImagesX(2);
effect.setImagesY(2);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
effect.setMaterial(mat);
}
use of com.jme3.effect.ParticleEmitter in project jmonkeyengine by jMonkeyEngine.
the class ParticleEmitter method read.
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule ic = im.getCapsule(this);
shape = (EmitterShape) ic.readSavable("shape", DEFAULT_SHAPE);
if (shape == DEFAULT_SHAPE) {
// Prevent reference to static
shape = shape.deepClone();
}
meshType = ic.readEnum("meshType", ParticleMesh.Type.class, ParticleMesh.Type.Triangle);
int numParticles = ic.readInt("numParticles", 0);
enabled = ic.readBoolean("enabled", true);
particlesPerSec = ic.readFloat("particlesPerSec", 0);
lowLife = ic.readFloat("lowLife", 0);
highLife = ic.readFloat("highLife", 0);
gravity = (Vector3f) ic.readSavable("gravity", null);
imagesX = ic.readInt("imagesX", 1);
imagesY = ic.readInt("imagesY", 1);
startColor = (ColorRGBA) ic.readSavable("startColor", null);
endColor = (ColorRGBA) ic.readSavable("endColor", null);
startSize = ic.readFloat("startSize", 0);
endSize = ic.readFloat("endSize", 0);
worldSpace = ic.readBoolean("worldSpace", false);
this.setIgnoreTransform(worldSpace);
facingVelocity = ic.readBoolean("facingVelocity", false);
faceNormal = (Vector3f) ic.readSavable("faceNormal", new Vector3f(Vector3f.NAN));
selectRandomImage = ic.readBoolean("selectRandomImage", false);
randomAngle = ic.readBoolean("randomAngle", false);
rotateSpeed = ic.readFloat("rotateSpeed", 0);
switch(meshType) {
case Point:
particleMesh = new ParticlePointMesh();
this.setMesh(particleMesh);
break;
case Triangle:
particleMesh = new ParticleTriMesh();
this.setMesh(particleMesh);
break;
default:
throw new IllegalStateException("Unrecognized particle type: " + meshType);
}
this.setNumParticles(numParticles);
// particleMesh.initParticleData(this, particles.length);
// particleMesh.setImagesXY(imagesX, imagesY);
particleInfluencer = (ParticleInfluencer) ic.readSavable("influencer", DEFAULT_INFLUENCER);
if (particleInfluencer == DEFAULT_INFLUENCER) {
particleInfluencer = particleInfluencer.clone();
}
if (im.getFormatVersion() == 0) {
// find it in the controls and take it out, then add the proper one in
for (int i = 0; i < controls.size(); i++) {
Object obj = controls.get(i);
if (obj instanceof ParticleEmitter) {
controls.remove(i);
// now add the proper one in
controls.add(new ParticleEmitterControl(this));
break;
}
}
// compatability before gravity was not a vector but a float
if (gravity == null) {
gravity = new Vector3f();
gravity.y = ic.readFloat("gravity", 0);
}
} else {
// since the parentEmitter is not loaded, it must be
// loaded separately
control = getControl(ParticleEmitterControl.class);
control.parentEmitter = this;
}
}
use of com.jme3.effect.ParticleEmitter in project jmonkeyengine by jMonkeyEngine.
the class ParticlePointMesh method initParticleData.
@Override
public void initParticleData(ParticleEmitter emitter, int numParticles) {
setMode(Mode.Points);
this.emitter = emitter;
// set positions
FloatBuffer pb = BufferUtils.createVector3Buffer(numParticles);
//if the buffer is already set only update the data
VertexBuffer buf = getBuffer(VertexBuffer.Type.Position);
if (buf != null) {
buf.updateData(pb);
} else {
VertexBuffer pvb = new VertexBuffer(VertexBuffer.Type.Position);
pvb.setupData(Usage.Stream, 3, Format.Float, pb);
setBuffer(pvb);
}
// set colors
ByteBuffer cb = BufferUtils.createByteBuffer(numParticles * 4);
buf = getBuffer(VertexBuffer.Type.Color);
if (buf != null) {
buf.updateData(cb);
} else {
VertexBuffer cvb = new VertexBuffer(VertexBuffer.Type.Color);
cvb.setupData(Usage.Stream, 4, Format.UnsignedByte, cb);
cvb.setNormalized(true);
setBuffer(cvb);
}
// set sizes
FloatBuffer sb = BufferUtils.createFloatBuffer(numParticles);
buf = getBuffer(VertexBuffer.Type.Size);
if (buf != null) {
buf.updateData(sb);
} else {
VertexBuffer svb = new VertexBuffer(VertexBuffer.Type.Size);
svb.setupData(Usage.Stream, 1, Format.Float, sb);
setBuffer(svb);
}
// set UV-scale
FloatBuffer tb = BufferUtils.createFloatBuffer(numParticles * 4);
buf = getBuffer(VertexBuffer.Type.TexCoord);
if (buf != null) {
buf.updateData(tb);
} else {
VertexBuffer tvb = new VertexBuffer(VertexBuffer.Type.TexCoord);
tvb.setupData(Usage.Stream, 4, Format.Float, tb);
setBuffer(tvb);
}
updateCounts();
}
use of com.jme3.effect.ParticleEmitter in project jmonkeyengine by jMonkeyEngine.
the class ParticleTriMesh method initParticleData.
// private Particle[] particlesCopy;
@Override
public void initParticleData(ParticleEmitter emitter, int numParticles) {
setMode(Mode.Triangles);
this.emitter = emitter;
// particlesCopy = new Particle[numParticles];
// set positions
FloatBuffer pb = BufferUtils.createVector3Buffer(numParticles * 4);
// if the buffer is already set only update the data
VertexBuffer buf = getBuffer(VertexBuffer.Type.Position);
if (buf != null) {
buf.updateData(pb);
} else {
VertexBuffer pvb = new VertexBuffer(VertexBuffer.Type.Position);
pvb.setupData(Usage.Stream, 3, Format.Float, pb);
setBuffer(pvb);
}
// set colors
ByteBuffer cb = BufferUtils.createByteBuffer(numParticles * 4 * 4);
buf = getBuffer(VertexBuffer.Type.Color);
if (buf != null) {
buf.updateData(cb);
} else {
VertexBuffer cvb = new VertexBuffer(VertexBuffer.Type.Color);
cvb.setupData(Usage.Stream, 4, Format.UnsignedByte, cb);
cvb.setNormalized(true);
setBuffer(cvb);
}
// set texcoords
FloatBuffer tb = BufferUtils.createVector2Buffer(numParticles * 4);
uniqueTexCoords = false;
for (int i = 0; i < numParticles; i++) {
tb.put(0f).put(1f);
tb.put(1f).put(1f);
tb.put(0f).put(0f);
tb.put(1f).put(0f);
}
tb.flip();
buf = getBuffer(VertexBuffer.Type.TexCoord);
if (buf != null) {
buf.updateData(tb);
} else {
VertexBuffer tvb = new VertexBuffer(VertexBuffer.Type.TexCoord);
tvb.setupData(Usage.Static, 2, Format.Float, tb);
setBuffer(tvb);
}
// set indices
ShortBuffer ib = BufferUtils.createShortBuffer(numParticles * 6);
for (int i = 0; i < numParticles; i++) {
int startIdx = (i * 4);
// triangle 1
ib.put((short) (startIdx + 1)).put((short) (startIdx + 0)).put((short) (startIdx + 2));
// triangle 2
ib.put((short) (startIdx + 1)).put((short) (startIdx + 2)).put((short) (startIdx + 3));
}
ib.flip();
buf = getBuffer(VertexBuffer.Type.Index);
if (buf != null) {
buf.updateData(ib);
} else {
VertexBuffer ivb = new VertexBuffer(VertexBuffer.Type.Index);
ivb.setupData(Usage.Static, 3, Format.UnsignedShort, ib);
setBuffer(ivb);
}
updateCounts();
}
Aggregations