AssetLinkNode does not save children location

In this example I add a child to AssetLinkNode with local translation (0,2,0) but when I save and load it again children are transformed to (0,0,0).

public class TestAssetLinkNode extends SimpleApplication {

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

    @Override
    public void simpleInitApp() {
        AssetLinkNode loaderNode=new AssetLinkNode();
        ModelKey modelKey = new ModelKey("Models/MonkeyHead/MonkeyHead.mesh.xml");
        Spatial spatial = assetManager.loadModel(modelKey);
        spatial.setLocalTranslation(0, 2, 0);
        loaderNode.attachLinkedChild(spatial, modelKey);
        rootNode.attachChild(loaderNode);
        
        //save and load the loaderNode
        try {
            //export to byte array
            ByteArrayOutputStream bout=new ByteArrayOutputStream();
            BinaryExporter.getInstance().save(loaderNode, bout);
            //import from byte array, automatically loads the monkeyhead from file
            ByteArrayInputStream bin=new ByteArrayInputStream(bout.toByteArray());
            BinaryImporter imp=BinaryImporter.getInstance();
            imp.setAssetManager(assetManager);
            Node newLoaderNode=(Node)imp.load(bin);
            rootNode.attachChild(newLoaderNode);
            System.out.println("location of child after save and load:" + newLoaderNode.getChild(0).getLocalTranslation());
               
            
        } catch (IOException ex) {
            Logger.getLogger(TestAssetLinkNode.class.getName()).log(Level.SEVERE, null, ex);
        }

        // sunset light
        DirectionalLight dl = new DirectionalLight();
        dl.setDirection(new Vector3f(-0.1f,-0.7f,1).normalizeLocal());
        dl.setColor(new ColorRGBA(0.44f, 0.30f, 0.20f, 1.0f));
        rootNode.addLight(dl);
        
        // white ambient light
        dl = new DirectionalLight();
        dl.setDirection(new Vector3f(1, -0.5f,-0.1f).normalizeLocal());
        dl.setColor(new ColorRGBA(0.50f, 0.40f, 0.50f, 1.0f));
        rootNode.addLight(dl);
    }
}

output: location of child after save and load:(0.0, 0.0, 0.0)

if we are supposed to add just one child, and modify location directly on AssetLinkNode then why do we have an array list of children at all, shouldn’t it be just a single assetLoaderKey instead of a list ?

I always change the AssetLink rotation and translation instead of the child.

I use this feature to add different types of shields to the space ships depending on your ship build. Since the ship and shield nodes are both at 0,0,0 it works out great.

1 Like