EffectTrack now disable and cull the emitter once all particles are gone
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9625 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
2ab5e4abbe
commit
ef98888ce7
@ -36,6 +36,12 @@ import com.jme3.export.InputCapsule;
|
|||||||
import com.jme3.export.JmeExporter;
|
import com.jme3.export.JmeExporter;
|
||||||
import com.jme3.export.JmeImporter;
|
import com.jme3.export.JmeImporter;
|
||||||
import com.jme3.export.OutputCapsule;
|
import com.jme3.export.OutputCapsule;
|
||||||
|
import com.jme3.renderer.RenderManager;
|
||||||
|
import com.jme3.renderer.ViewPort;
|
||||||
|
import com.jme3.scene.Spatial;
|
||||||
|
import com.jme3.scene.Spatial.CullHint;
|
||||||
|
import com.jme3.scene.control.AbstractControl;
|
||||||
|
import com.jme3.scene.control.Control;
|
||||||
import com.jme3.util.TempVars;
|
import com.jme3.util.TempVars;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -64,19 +70,45 @@ public class EffectTrack implements Track {
|
|||||||
private float length = 0;
|
private float length = 0;
|
||||||
private boolean emitted = false;
|
private boolean emitted = false;
|
||||||
private boolean initialized = false;
|
private boolean initialized = false;
|
||||||
|
private boolean stopRequested = false;
|
||||||
|
|
||||||
|
//control responsible for disable and cull the emitter once all particles are gone
|
||||||
|
private AbstractControl killParticles = new AbstractControl() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void controlUpdate(float tpf) {
|
||||||
|
if (emitter.getNumVisibleParticles() == 0) {
|
||||||
|
emitter.setCullHint(CullHint.Always);
|
||||||
|
emitter.setEnabled(false);
|
||||||
|
emitter.removeControl(killParticles);
|
||||||
|
stopRequested = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void controlRender(RenderManager rm, ViewPort vp) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Control cloneForSpatial(Spatial spatial) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
//Anim listener that stops the Emmitter when the animation is finished or changed.
|
//Anim listener that stops the Emmitter when the animation is finished or changed.
|
||||||
private class OnEndListener implements AnimEventListener {
|
private class OnEndListener implements AnimEventListener {
|
||||||
|
|
||||||
public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {
|
public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {
|
||||||
stop();
|
if(!stopRequested){
|
||||||
|
stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {
|
public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {
|
||||||
stop();
|
if(!stopRequested){
|
||||||
|
stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default constructor only for serialization
|
* default constructor only for serialization
|
||||||
@ -84,7 +116,6 @@ public class EffectTrack implements Track {
|
|||||||
public EffectTrack() {
|
public EffectTrack() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and EffectTrack
|
* Creates and EffectTrack
|
||||||
* @param emitter the emmitter of the track
|
* @param emitter the emmitter of the track
|
||||||
@ -125,20 +156,27 @@ public class EffectTrack implements Track {
|
|||||||
//checking fo time to trigger the effect
|
//checking fo time to trigger the effect
|
||||||
if (!emitted && time >= startOffset) {
|
if (!emitted && time >= startOffset) {
|
||||||
emitted = true;
|
emitted = true;
|
||||||
|
stopRequested = false;
|
||||||
|
emitter.setCullHint(CullHint.Dynamic);
|
||||||
|
emitter.setEnabled(true);
|
||||||
//if the emitter has 0 particles per seconds emmit all particles in one shot
|
//if the emitter has 0 particles per seconds emmit all particles in one shot
|
||||||
if (particlesPerSeconds == 0) {
|
if (particlesPerSeconds == 0) {
|
||||||
emitter.emitAllParticles();
|
emitter.emitAllParticles();
|
||||||
|
emitter.addControl(killParticles);
|
||||||
|
stopRequested = true;
|
||||||
} else {
|
} else {
|
||||||
//else reset its former particlePerSec value to let it emmit.
|
//else reset its former particlePerSec value to let it emmit.
|
||||||
emitter.setParticlesPerSec(particlesPerSeconds);
|
emitter.setParticlesPerSec(particlesPerSeconds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//stops the emmiter to emit.
|
//stops the emmiter to emit.
|
||||||
private void stop() {
|
private void stop() {
|
||||||
emitter.setParticlesPerSec(0);
|
emitter.setParticlesPerSec(0);
|
||||||
emitted = false;
|
emitted = false;
|
||||||
|
emitter.addControl(killParticles);
|
||||||
|
stopRequested = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -157,9 +195,9 @@ public class EffectTrack implements Track {
|
|||||||
public Track clone() {
|
public Track clone() {
|
||||||
return new EffectTrack(emitter, length, startOffset);
|
return new EffectTrack(emitter, length, startOffset);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return the emitter used by this track
|
* @return the emitter used by this track
|
||||||
*/
|
*/
|
||||||
@ -208,7 +246,7 @@ public class EffectTrack implements Track {
|
|||||||
* Internal use only serialization
|
* Internal use only serialization
|
||||||
* @param im importer
|
* @param im importer
|
||||||
* @throws IOException Exception
|
* @throws IOException Exception
|
||||||
*/
|
*/
|
||||||
public void read(JmeImporter im) throws IOException {
|
public void read(JmeImporter im) throws IOException {
|
||||||
InputCapsule in = im.getCapsule(this);
|
InputCapsule in = im.getCapsule(this);
|
||||||
emitter = (ParticleEmitter) in.readSavable("emitter", null);
|
emitter = (ParticleEmitter) in.readSavable("emitter", null);
|
||||||
@ -217,8 +255,4 @@ public class EffectTrack implements Track {
|
|||||||
length = in.readFloat("length", length);
|
length = in.readFloat("length", length);
|
||||||
startOffset = in.readFloat("startOffset", 0);
|
startOffset = in.readFloat("startOffset", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user