@t0neg0d I had trouble to getting the standard read write support up and running. So I improved it (so I hope).
At least it works for my fire example to save out as a j3o and load as a j3o. Any reason you did not derive Emitter from AbstractControl?
But to get this going I had to set the asset manager for the binary importer, is there a better way of doing this?
[java]
BinaryExporter.getInstance().save(n, new File(“spriteflames.j3o”));
BinaryImporter bim = BinaryImporter.getInstance();
bim.setAssetManager(assetManager);
Node nn = (Node) bim.load(new File(“spriteflames.j3o”));
[/java]
in write Add spatial saving :
[java]
public void write(JmeExporter ex) throws IOException {
OutputCapsule oc = ex.getCapsule(this);
oc.writeSavableArrayList(new ArrayList(influencers), “influencers”, null);
oc.write(name, "name", null);
oc.write(spatial, "spatial", null);
[/java]
and here is the working read, reworked to only call setters where needed, not fully optimized (see the lower part with the many if’s), and the crucial spatial.addControl():
[java]
@Override
public void read(JmeImporter im) throws IOException {
InputCapsule ic = im.getCapsule(this);
name = ic.readString(“name”, generateName());
spatial = (Spatial) ic.readSavable(“spatial”, null);
maxParticles = ic.readInt(“maxParticles”, 30);//needed here as initparticles relies on maxParticles
userDefinedMat = (Material)ic.readSavable("userDefinedMat", null);
testMat = (Material)ic.readSavable("testMat", null);
mat = (Material)ic.readSavable("mat", null);
tex = (Texture) ic.readSavable("tex", null);
applyLightingTransform = ic.readBoolean("applyLightingTransform", false);
uniformName = ic.readString("uniformName", null);
// Emitter animation
esAnimName = ic.readString("esAnimName", "");
esAnimSpeed = ic.readFloat("esAnimSpeed", 1);
esAnimBlendTime = ic.readFloat("esAnimBlendTime", 1);
Mesh emitterShapeMesh = (Mesh)ic.readSavable("emitterShape", new TriangleEmitterShape(1));
if(emitterShapeMesh != null){
emitterShape.setShape(this, emitterShapeMesh);
}
esAnimNode = (Node)ic.readSavable("esAnimNode", null);
esNodeExists = ic.readBoolean("esNodeExists", true);
esAnimLoopMode = LoopMode.valueOf(ic.readString("esAnimLoopMode", LoopMode.Loop.name()));
if (esAnimNode != null) {
setShape(esAnimNode, this.esNodeExists);
setEmitterAnimation(esAnimName, esAnimSpeed, esAnimBlendTime, esAnimLoopMode);
} else
setShape(emitterShape.getMesh());
try {
particleType = Class.forName(ic.readString("particleType", ParticleDataTriMesh.class.getName()));
} catch (IOException | ClassNotFoundException ex) {
particleType = ParticleDataTriMesh.class;
}
ptAnimNode = (Node)ic.readSavable("ptAnimNode", null);
// Particle animation
ptAnimName = ic.readString("ptAnimName", "");
ptAnimSpeed = ic.readFloat("ptAnimSpeed", 1);
ptAnimBlendTime = ic.readFloat("ptAnimBlendTime", 1);
ptAnimLoopMode = LoopMode.valueOf(ic.readString("ptAnimLoopMode", LoopMode.Loop.name()));
template = (Mesh)ic.readSavable("template", null);
if (ptAnimNode != null) {
setParticleType(particleType, ptAnimNode);
setParticleAnimation(ptAnimName, ptAnimSpeed, ptAnimBlendTime, ptAnimLoopMode);
} else
setParticleType(particleType, template);
String ip = ic.readString("interpolation", null);
if(ip != null){
interpolation = Interpolation.getInterpolationByName(ip);
} else {
interpolation = Interpolation.linear;
}
forceMin = ic.readFloat("forceMin", .15f);
forceMax = ic.readFloat("forceMax", .5f);
lifeMin = ic.readFloat("lifeMin", 0.999f);
lifeMax = ic.readFloat("lifeMax", 0.999f);
emissionsPerSecond = ic.readInt("emissionsPerSecond", 20);
setEmissionsPerSecond(emissionsPerSecond);
particlesPerEmission = ic.readInt("particlesPerEmission", 1);
setParticlesPerEmission(particlesPerEmission);
useRandomEmissionPoint = ic.readBoolean("useRandomEmissionPoint", false);
useSequentialEmissionFace = ic.readBoolean("useSequentialEmissionFace", false);
useSequentialSkipPattern = ic.readBoolean("useSequentialSkipPattern", false);
particlesFollowEmitter = ic.readBoolean("particlesFollowEmitter", false);
useStaticParticles = ic.readBoolean("useStaticParticles", false);
velocityStretchFactor = ic.readFloat("velocityStretchFactor", 0.35f);
useVelocityStretching = ic.readBoolean("useVelocityStretching", false);
stretchAxis = ForcedStretchAxis.valueOf(ic.readString("stretchAxis", ForcedStretchAxis.Y.name()));
particleEmissionPoint = ParticleEmissionPoint.valueOf(ic.readString("particleEmissionPoint", ParticleEmissionPoint.Particle_Center.name()));
billboardMode = BillboardMode.valueOf(ic.readString("billboardMode", BillboardMode.Camera.name()));
directionType = DirectionType.valueOf(ic.readString("directionType", EmitterMesh.DirectionType.Random.name()));
TEST_EMITTER = ic.readBoolean("TEST_EMITTER", false);
TEST_PARTICLES = ic.readBoolean("TEST_PARTICLES", false);
influencers = new SafeArrayList<ParticleInfluencer>(ParticleInfluencer.class, ic.readSavableArrayList("influencers", null));
// particleNode.setMaterial(mat);
initParticles(particleType, template);
// userDefinedMat = (Material)ic.readSavable(“userDefinedMat”, null);
// mat = userDefinedMat;
// applyLightingTransform = ic.readBoolean(“applyLightingTransform”, false);
// uniformName = ic.readString(“uniformName”, null);
texturePath = ic.readString("texturePath", null);
spriteWidth = ic.readFloat("spriteWidth", 50);
spriteHeight = ic.readFloat("spriteHeight", 50);
spriteCols = ic.readInt("spriteCols", 1);
spriteRows = ic.readInt("spriteRows", 1);
mesh.setImagesXY(spriteCols,spriteRows);
// setSprite(texturePath, spriteCols, spriteRows);
enabled = ic.readBoolean(“enabled”, false);
if (esAnimControl != null) {
if (!esAnimName.equals("")) {
esAnimChannel.setAnim(esAnimName, esAnimBlendTime);
esAnimChannel.setSpeed(esAnimSpeed);
}
}
if (ptAnimControl != null) {
if (!ptAnimName.equals("")) {
ptAnimChannel.setAnim(ptAnimName, ptAnimBlendTime);
ptAnimChannel.setSpeed(ptAnimSpeed);
}
}
if (particleNode.getChildren().isEmpty()) {
Geometry geom = new Geometry();
geom.setMesh(mesh);
particleNode.attachChild(geom);
particleNode.setMaterial(mat);
particleNode.setQueueBucket(RenderQueue.Bucket.Transparent);
}
if (emitterTestNode.getChildren().isEmpty()) {
Geometry testGeom = new Geometry();
testGeom.setMesh(emitterShape.getMesh());
emitterTestNode.attachChild(testGeom);
emitterTestNode.setMaterial(testMat);
}
if (particleTestNode.getChildren().isEmpty()) {
Geometry testPGeom = new Geometry();
testPGeom.setMesh(mesh);
particleTestNode.attachChild(testPGeom);
particleTestNode.setMaterial(testMat);
}
emitterInitialized = true;
if(spatial != null )
spatial.addControl(this);
// initialize(assetManager);
// setEnabled(enabled);
}
[/java]