Hello,
I am trying to load two .j3o models. One is a terrain made with the terrain editor, and it works fine. The other is a model I imported (the Ninja), and the same code that loads the terrain j3o does not work for the Ninja model. According to the tutorials, I am using the right commands, though I do find it confusing that some objects don’t seem to be added to the root node or any other node as far as I can tell. Also, I can’t find an explanation for the following code in the tutorial:
player_model = (Node) assetManager.loadModel(“Models/Ninja/Ninja.j3o”);
why is (Node) in there? Why not just:
player_model = assetManager.loadModel(“Models/Ninja/Ninja.j3o”);
In any event, the model refuses to load either way, even though it seems to have been imported properly ( I could see it in the import preview window). Can anyone help me understand this? Here is my code:
[java]
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Spatial;
import com.jme3.math.ColorRGBA;
import com.jme3.input.ChaseCamera;
import com.jme3.scene.Node;
/**
- test
-
@author normenhansen
*/
public class Main extends SimpleApplication {
public static void main(String[] args) {
Main app = new Main();
app.start();
}
private Spatial scene_model;
private Spatial player_model;
@Override
public void simpleInitApp() {
init_cameras();
init_models();
}
private void init_models() {
player_model = (Node) assetManager.loadModel("Models/Ninja/Ninja.j3o");
player_model.setLocalScale(10f);
player_model.setLocalTranslation(0, 0, 0);
rootNode.attachChild(player_model);
scene_model = assetManager.loadModel("Scenes/TerrainTest.j3o");
scene_model.setLocalTranslation(0, -100, 0);
scene_model.setLocalScale(10f, 0.5f, 10f);
rootNode.attachChild(scene_model);
}
private void init_cameras() {
viewPort.setBackgroundColor(new ColorRGBA(0.7f,0.8f,1f,1));
flyCam.setMoveSpeed(50);
}
@Override
public void simpleUpdate(float tpf) {
//TODO: add update code
}
@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
}
[/java]
Thanks in advance!
Matt