Problem with loading model

Hi, I’m just testing easy method to render few trees. I got few Nodes on my scene - all named Tree, and I’m getting location of each node, and placing there a tree model. It work only for 1 - only 1 tree is placing at 1 node’s coords. What’s wrong?

        [java]    Node trees;
            trees = (Node) map.getChild("Trees");
            System.out.println(trees);
            
            Node tree;
            Node treeModel  = (Node) assetManager.loadModel("Models/Tree2/Tree2.j3o");
            for (int i = 0; i < 2; i++) {
                tree = (Node) trees.getChild(i);
                treeModel.setLocalTranslation(tree.getWorldTranslation());
                map.attachChild(treeModel);
}[/java]

You keep reattaching the same treeModel.

1 Like

I tried using:
[java]treeModel.setName(“Tree2-”+i); [/java]but still no effect

[java]map.attachChild(treeModel.clone());[/java]

1 Like

You keep reattaching the same treeModel instance every time. A treeModel instance can only have one parent at a time.

This is really coming down to more of a Java programming issue than a JME issue. It seems like you are getting confused about what an instance is. Changing the name of an instance doesn’t make it a new instance.

Maybe instead, you want to load the tree multiple times?

1 Like

Ok, fixed, thanks