I created a particle node for flowing water effects, and passing a direction for the effects to display flowing down a block face, not sure if there is a bug or having missed something in my code, but the particle node isn’t working correctly.
Particles facing East & West ([java]Vector3f(1, 0, 0) || Vector3f(-1, 0, 0)[/java]) using the [java]setFaceNormal(direction)[/java] not displaying, any other facing direction, North, South even diagonal direction are working correctly.
[java]package mygame;
import com.jme3.effect.ParticleEmitter;
import com.jme3.material.Material;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
-
@author Wayne Barron
*/
public abstract class AbstractCellularEffectsNode extends Node {protected final ParticleEmitter emitter;
protected float waitTimer, lastTimer = 0;protected abstract void update();
public AbstractCellularEffectsNode(ParticleEmitter emitter, Material material, String name) {
this(emitter, material, name, 1);
}public AbstractCellularEffectsNode(ParticleEmitter emitter, Material material, String name, float timer) {
super(name);
this.emitter = emitter;
this.waitTimer = timer;
this.emitter.setMaterial(material);
}@Override
public void updateLogicalState(float tpf) {
super.updateLogicalState(tpf);lastTimer += tpf; if (lastTimer > waitTimer) { lastTimer = 0; update(); }
}
public static String format(String name, int x, int z, int dir) {
return String.format("%s[%d%d][%d]", name, x, z, dir);
}public void setEnabled(boolean enabled) {
emitter.setEnabled(enabled);
if (enabled) {
emitter.setCullHint(Spatial.CullHint.Never);
} else {
emitter.setCullHint(Spatial.CullHint.Always);
}
}public void remove() {
if (emitter != null) {
emitter.setParticlesPerSec(0);
if (emitter.getNumVisibleParticles() == 0) {
emitter.killAllParticles();
boolean removeEmitter = emitter.removeFromParent();
boolean removeNode = removeFromParent();
if (!removeNode || !removeEmitter) {
Logger.getLogger(this.getClass().getName()).log(Level.WARNING,
String.format("%s%nSelf terminate was unsuccessful%nNode Removed? %s%nParticles Removed? %s",
toString(),
removeNode,
removeEmitter));
}
}
}
}
}
[/java]
[java]package mygame;
import com.jme3.asset.AssetManager;
import com.jme3.effect.ParticleEmitter;
import com.jme3.effect.ParticleMesh.Type;
import com.jme3.math.Vector3f;
import static mygame.AbstractCellularEffectsNode.format;
/**
*
-
@author Wayne Barron
*/
public class EffectsWaterFlowNode extends AbstractCellularEffectsNode {private final float size, offset = 0.01f;
private static final String id = “WaterFlowNode”;public EffectsWaterFlowNode(AssetManager assetManager, Vector3f direction, String name, float size) {
super(new ParticleEmitter(“WaterFlow”, Type.Triangle, 1),
assetManager.loadMaterial(“Materials/WaterFlow.j3m”), name, 2);this.size = size; applyParameters(direction);
}
@Override
protected void update() {
remove();
}public static String getUID(int x, int y, int dir) {
return format(id, x, y, dir);
}private void applyParameters(Vector3f direction) {
emitter.setImagesX(1);
emitter.setImagesY(3);
emitter.setLowLife(1);
emitter.setHighLife(1);
emitter.setEndSize(size);
emitter.setStartSize(size);
emitter.setInWorldSpace(false);
emitter.setFaceNormal(direction);
emitter.setGravity(new Vector3f(0, 10, 0));
emitter.getParticleInfluencer().setVelocityVariation(0);
emitter.getParticleInfluencer().setInitialVelocity(direction);emitter.updateLogicalState(0); emitter.updateGeometricState(); emitter.setLocalTranslation(direction.mult(size + offset).subtract(0, size, 0)); attachChild(emitter);
}
}
[/java]