BinaryImporter failed for j3o model and DirectionalLight

hello, everyone

I use BinaryExporter to export Jaime.j3o model and DirectionalLight, but use BinaryImporter to import failed, Jaime has no skin and AnimControl, DirectionalLight also has bug.
I need help.

JmeExporter is an interface. Which class were you using that implements JmeExporter? And what is a “bug”. It could mean a million things. Please provide as much information as possible.

My Server scene rootNode has a green floor,jaime,DirectionalLight, I transfer all spatial and light over network, Client simpleUpdate() reload jaime without skin and anim, and floor color is not green.
can you help me? thank you

It seems that sample of code, screenshot and logs would be useful to understand your problem.

Meaning he’s invisible? Or?

Is the floor green because of a texture?

…does the client also have the textures for Jaime and the floor?

public class TestSpace1 extends SimpleApplication {

public static void main(String[] args) {
    TestSpace1 app = new TestSpace1();
    app.start();
}

@Override
public void simpleInitApp() {
    flyCam.setEnabled(false);
    cam.setLocation(new Vector3f(0.0f, 12.0f, 21.0f));
    //viewPort.setBackgroundColor(new ColorRGBA(0.2118f, 0.0824f, 0.6549f, 1.0f));

    startWorld2();
}

DirectionalLight sun;
Geometry floor;

private void startWorld2() {
    // create light
    sun = new DirectionalLight();
    sun.setDirection((new Vector3f(-0.7f, -0.3f, -0.5f)).normalizeLocal());
    sun.setColor(ColorRGBA.White);

    Material materialGreen = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    materialGreen.setBoolean("UseMaterialColors", true);
    materialGreen.setBoolean("HardwareShadows", true);
    materialGreen.setColor("Diffuse", new ColorRGBA(0.0431f, 0.7725f, 0.0078f, 1.0f));
    materialGreen.setColor("Specular", ColorRGBA.White);
    materialGreen.setFloat("Shininess", 64.0f);

    floor = new Geometry("floor", new Box(22.0f, 0.5f, 22.0f));
    floor.setShadowMode(RenderQueue.ShadowMode.Receive);
    floor.setLocalTranslation(0.0f, -0.5f, 0.0f);
    floor.setMaterial(materialGreen);

    rootNode.attachChild(floor);

    Vector3f centralForce = new Vector3f(0, 8, 0);
    cam.lookAt(centralForce, Vector3f.UNIT_Y);
}

private final float syncFrequency = 0.25f;
float syncTimer = 0;

@Override
public void simpleUpdate(float tpf) {
    syncTimer += tpf;
    if (syncTimer >= syncFrequency) {
        rootNode.detachAllChildren();
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            BinaryExporter exp = new BinaryExporter();
            exp.save(sun, baos);

            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            BinaryImporter imp = new BinaryImporter();
            imp.setAssetManager(assetManager);
            Light sunReload = (Light) imp.load(bais, null, null);

            rootNode.removeLight(sunReload);
            rootNode.addLight(sunReload);
        } catch (IOException ie) {
            ie.printStackTrace();
        }

        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            BinaryExporter exp = new BinaryExporter();
            exp.save(floor, baos);

            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            BinaryImporter imp = new BinaryImporter();
            imp.setAssetManager(assetManager);
            Geometry floorReload = (Geometry) imp.load(bais, null, null);

            rootNode.detachChild(floorReload);
            rootNode.attachChild(floorReload);
        } catch (IOException ie) {
            ie.printStackTrace();
        }
        syncTimer = 0;
    }
}

}

public class TestOgreConvert extends SimpleApplication {

public static void main(String[] args) {
    TestOgreConvert app = new TestOgreConvert();
    app.start();
}

Spatial jaime;

@Override
public void simpleInitApp() {
    jaime = assetManager.loadModel("Models/Jaime/Jaime.j3o");
    AnimControl control = jaime.getControl(AnimControl.class);
    AnimChannel chan = control.createChannel();
    chan.setAnim("Walk");

    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.White);
    dl.setDirection(new Vector3f(0, -1, -1).normalizeLocal());
    rootNode.addLight(dl);
}

private final float syncFrequency = 0.25f;
float syncTimer = 0;

@Override
public void simpleUpdate(float tpf) {
    syncTimer += tpf;
    if (syncTimer >= syncFrequency) {
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            BinaryExporter exp = new BinaryExporter();
            exp.save(jaime, baos);

            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            BinaryImporter imp = new BinaryImporter();
            imp.setAssetManager(assetManager);
            Node jaimelReloaded = (Node) imp.load(bais, null, null);

            rootNode.detachChild(jaimelReloaded);
            rootNode.attachChild(jaimelReloaded);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        syncTimer = 0;
    }
}

}

test found jaime lose aimcontrol, if transfer from server to client, jaime lose skin and aimcontrol

My project need to transfer spatials and lights from Server to Client, Client just show them, I found serialize/reserialize j3o and light Object not correct.

j3o lose skin and aimcontrol, light color are changed, so green floor be changed other colors

But in your last example, you never grabbed the anim control from the newly loaded object… so how would you know it’s missing?

If you mean that the object doesn’t animate when you use the old one… well that should be obvious because the old one is from the object you saved, not the object you loaded.

As for the skin, you didn’t answer my other question so my guess is that you don’t have the texture in the client’s assets and so it can’t find it. But I’m only guessing because you didn’t answer that question.

In my project, client received and load jaime object, first has skin, but run some second, skin be losed.
I hope aim control can be send, I found aim control implements Savable.
My client just be monitor, received spatials and lights from server and show its.

The client needs the spatials, materials etc on its drive, as paul mentioned. Server sends the client the information on what to load.

https://wiki.jmonkeyengine.org/jme3.html#multiplayer-networking

My project is not common multiplayer game, I used jme network to exchange action info between Server and Client, but Client must received spatials and lights from Server, I write my own network code to do it. spatials do work, except j3o model and light. So I need help, thank you

Serialization of these objects works fine. You’ve done something else wrong.

Like even your examples are wrong because they don’t actually show what you are saying. They have implementation problems but then you say that your real code doesn’t do the same thing.

Show us an example that should work and doesn’t and we’ll tell you what you did wrong.

Client load light from server, scene color are changed continue, I used jme sdk 3.2.4

this scene test reload jaime model received from server, jaime skin is white ?
Server send serialized spatials to Client, Client rootNode just detach/remove and attach/add in simpleUpdate(), network transfer is good
i think must modify jme-core some code, can you help me ? thank you

@xinguo there are a lot of possible reasons of such behavior. Such problems are normal when you try to do something complex and non-standard. The common way to find the root of issue is simplification of your code to the point where all works well and then trying to enrich it with necessary features step-by step.

First test:
I think light serialize has bugs, Client rootNode load local light , all is fine.
Second test:
if client reload j3o model serialized frequency slow, first can show skin, but show white after some second, so why ? but two boxs show fine

We can only debug code we can see…

I upload my some code, can you help me debug ?
how to upload my code ? it is 111M

Not all of it relates to your problem, though. Just post the areas that are related to your issue.