Although we recommend the jMonkeyPlatform for developing JME3 games, you can use any IDE (integrated development environment) such as NetBeans or Eclipse, and even work freely from the commandline. Here is a generic IDE-independent "getting started" tutorial.
This example shows how to set up and run a simple application (HelloJME3) that depends on the jMonkeyEngine3 libraries.
The directory structure will look as follows:
jme3/ jme3/lib jme3/src ... HelloJME3/ HelloJME3/lib HelloJME3/assets HelloJME3/src ...
To install the development version of jme3, , unzip the folder into a directory named jme3
. The filenames here are just an example, but they will always be something like jME3_xx-xx-2011
.
mkdir jme3 cd jme3 unzip jME3_01-18-2011.zip
Alternatively, you can build JME3 from the sources. (Recommended for JME3 developers.)
svn checkout https://jmonkeyengine.googlecode.com/svn/trunk/engine jme3 cd jme3 ant run cd ..
If you see a Test Chooser open now, the build was successful. Tip: Use ant
to build the libraries without running the demos.
First we set up the directory and source package structure for your game project. Note that the game project directory HelloJME3
is on the same level as your jme3
checkout. In this example, we create a Java package that we call hello
in the source directory.
mkdir HelloJME3 mkdir HelloJME3/src mkdir HelloJME3/src/hello
Next we copy the necessary JAR libraries. You only have to do this set of steps once every time you download a new JME3 build.
mkdir HelloJME3/build mkdir HelloJME3/lib cp jme3/jMonkeyEngine3.jar HelloJME3/lib cp jme3/lib/*.* HelloJME3/lib
If you have built JME3 from the sources, then the paths are different:
mkdir HelloJME3/build mkdir HelloJME3/lib cp jme3/dist/jMonkeyEngine3.jar HelloJME3/lib cp jme3/dist/*.* HelloJME3/lib
To test your setup, create the file HelloJME3/src/hello/HelloJME3.java
with any text editor, paste the following sample code, and save.
package hello; import com.jme3.app.SimpleApplication; import com.jme3.material.Material; import com.jme3.math.Vector3f; import com.jme3.scene.Geometry; import com.jme3.scene.shape.Box; import com.jme3.math.ColorRGBA; public class HelloJME3 extends SimpleApplication { public static void main(String[] args){ HelloJME3 app = new HelloJME3(); app.start(); } @Override public void simpleInitApp() { Box(Vector3f.ZERO, 1, 1, 1); Geometry geom = new Geometry("Box", b); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setColor("Color", ColorRGBA.Blue); geom.setMaterial(mat); rootNode.attachChild(geom); } }
We build the sample application into the build directory…
cd HelloJME3 javac -d build -cp "lib/eventbus-1.4.jar:lib/j-ogg-oggd.jar:lib/j-ogg-vorbisd.jar:lib/jME3-lwjgl-natives.jar:lib/jMonkeyEngine3.jar:lib/jbullet.jar:lib/jheora-jst-debug-0.6.0.jar:lib/jinput.jar:lib/jme3test.jar:lib/jme3testdata.jar:lib/lwjgl.jar:lib/nifty-1.3-SNAPSHOT.jar:lib/nifty-default-controls-1.3-SNAPSHOT.jar:lib/nifty-examples-1.3-SNAPSHOT.jar:lib/nifty-style-black-1.3-SNAPSHOT.jar:lib/nifty-style-grey-1.0.jar:lib/stack-alloc.jar:lib/vecmath.jar:lib/xmlpull-xpp3-1.1.4c.jar:." src/hello/HelloJME3.java
… and run it.
cd build java -cp "../lib/eventbus-1.4.jar:../lib/j-ogg-oggd.jar:../lib/j-ogg-vorbisd.jar:../lib/jME3-lwjgl-natives.jar:../lib/jMonkeyEngine3.jar:../lib/jbullet.jar:../lib/jheora-jst-debug-0.6.0.jar:../lib/jinput.jar:../lib/jme3test.jar:../lib/jme3testdata.jar:../lib/lwjgl.jar:../lib/nifty-1.3-SNAPSHOT.jar:../lib/nifty-default-controls-1.3-SNAPSHOT.jar:../lib/nifty-examples-1.3-SNAPSHOT.jar:../lib/nifty-style-black-1.3-SNAPSHOT.jar:../lib/nifty-style-grey-1.0.jar:../lib/stack-alloc.jar:../lib/vecmath.jar:../lib/xmlpull-xpp3-1.1.4c.jar:." hello/HelloJME3
Note: If you use Windows, the classpath separator is ";" instead of ":".
If a settings dialog pops up, confirm the default settings. You should now see a simple window with a 3-D cube. Use the mouse and the WASD keys to move. It works!
For media files and other assets, we recommend creating the following project structure:
cd HelloJME3 mkdir assets mkdir assets/Interface mkdir assets/Materials mkdir assets/MatDefs mkdir assets/Models mkdir assets/Scenes mkdir assets/Shaders mkdir assets/Sounds mkdir assets/Textures
This will allow the default assetManager to load media files stored in the assets
directory, like in this example:
import com.jme3.scene.Spatial; ... Spatial elephant = assetManager.loadModel("Models/Elephant/Elephant.meshxml"); rootNode.attachChild(elephant); ...
You will learn more about the asset manager and how to customize it later. For now feel free to structure your assets (images, textures, models) into further sub-directories, like in this example the assets/models/Elephant
directory that contains the elephant.meshxml
model and its materials.
Now follow the tutorials and write your first jMonkeyEngine game.