@edit : if you have the same problem see my second post
Hello, first sorry I speak wrong english,
my problem is the next :
I have a model and I want to load it at location(0, -10, 0).
This is my code :
[java]location = new Vector3f(0,-10,0);
Node toLoad = (Node)assetManager.loadModel(“myModel”);
toLoad.setLocalTranslation(location);
System.out.println(toLoad.getLocalTranslation().toString());//first test for know location of toLoad node
toLoad.setName(“modelLoaded” + numberOfModel);
System.out.println(toLoad.getLocalTranslation().toString());//second test for know location of toLoad node
rootNode.attachChild(toLoad);
System.out.println(toLoad.getLocalTranslation().toString());//third test for know location of toLoad node
numberOfModel ++;[/java]
My code don’t work as expected :
the node toLoad is loaded and I can see the models (a thank),
but models is on 0,0,0 location then I have set is location as 0, -10, 0.
Execution of the code:
(0.0, -10.0, 0.0)
(0.0, -10.0, 0.0)
oct. 30, 2012 9:27:21 PM com.jme3.scene.Node attachChild
INFO: Child (modelLoaded0) attached to this node (rootNode)
(0.0, -10.0, 0.0)
Thank you
Can you show us the rest of your code? That part of code there is acting as expected, your println confirms this, so it must be changing somewhere else.
What Sploreg says and
@gnales said:
but models is on 0,0,0 location then I have set is location as 0, -10, 0.
How do you know that it's at 0,0,0
put another one of the same model, and don’t change its translation, and see if there are 2 of them now. My guess is that your mesh is not centered and so looks wrong
@Sporeg : This is my code and I don’t move the node after
@nehon : because I have a landmark at 0,0,0
@wezrule :
@all : thank a lot for you help
I have founded the solution, :
Get the first child of model to load (here named “model”) and all work,
the working code :
[java]Vector3f location = new Vector3f(0,10,0);//System.out.println(“cas2”);}
Node model = (Node)assetManager.loadModel(“myModel”);
Node toLoad = (Node)model.getChild(“model”);//the name of the first child of the model here ‘model’
toLoad.setLocalTranslation(location);
toLoad.setName(“modelLoaded” + numberOfModel);
rootNode.attachChild(toLoad);
numberOfModel ++;[/java]
If you set the local translation of the parent, toLoad, to your location, the child will also be translated to (0,10,0). Unless you also translate the child ‘model’, then it will be doubly be translated. This tutorial on scene graphs might shed some light on what is happening.