The 3D model is ready for its journey into the 3D game world. Switch over to your BasicGame project in the jMonkeyEngine SDK again.
Make a copy of
Main.java
and name the classLoadModel.java
. Remember to also refactor the first line of themain()
method to:LoadModel app = new LoadModel ();
Replace the
simpleInitApp()
method with the following code snippet:public void simpleInitApp() { Spatial mymodel = assetManager.loadModel( "Textures/MyModel/mymodel.mesh.xml"); rootNode.attachChild(mymodel); DirectionalLight sun = new DirectionalLight(); sun.setDirection((new Vector3f(-0.5f, -0.5f, -0.5f))); sun.setColor(ColorRGBA.White); rootNode.addLight(sun); }
Since the load()
method returns both nodes and geometries, you load models as generic Spatials. Run the application and have a look at your loaded model.
The same loading method also works with the Wavefront .obj
file. Replace the path, and try it yourself:
Spatial mymodel = assetManager...