I followed this tutorial (http://www.jmonkeyengine.com/wiki/doku.php?id=exporting_.obj_models_from_blender) and I receive errors when trying to run the application. Here is the code and errors:
import com.jme.app.AbstractGame;
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingSphere;
import com.jme.input.FirstPersonHandler;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.TriMesh;
import com.jme.util.export.binary.BinaryImporter;
import com.jmex.model.converters.ObjToJme;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;
public class TestObjJmeWrite extends SimpleGame {
public static void main(String[] args) {
TestObjJmeWrite app = new TestObjJmeWrite();
app.setDialogBehaviour(AbstractGame.FIRSTRUN_OR_NOCONFIGFILE_SHOW_PROPS_DIALOG);
app.start();
}
protected void simpleInitGame() {
ObjToJme converter = new ObjToJme();
try {
URL objFile = TestObjJmeWrite.class.getClassLoader().getResource("Viper2.obj");
converter.setProperty("mtllib", objFile);
converter.setProperty("texdir", objFile);
ByteArrayOutputStream BO = new ByteArrayOutputStream();
System.out.println("Starting to convert .obj to .jme");
converter.convert(objFile.openStream(), BO);
//load as a TriMesh if single object
TriMesh model = (TriMesh) BinaryImporter.getInstance().load(
new ByteArrayInputStream(BO.toByteArray()));
//load as a node if multiple objects
//Node model=(Node)BinaryImporter.getInstance().load(
// new ByteArrayInputStream(BO.toByteArray()));
model.setModelBound(new BoundingSphere());
model.updateModelBound();
rootNode.attachChild(model);
} catch (IOException e) {
e.printStackTrace();
}
display.getRenderer().setBackgroundColor(ColorRGBA.gray);
input = new FirstPersonHandler(cam, 3, 1);
//needed for specular lighting(reflective light)
lightState.setSeparateSpecular(true);
}
}
Errors:
Aug 18, 2008 10:25:51 AM com.jme.app.BaseGame start
INFO: Application started.
Aug 18, 2008 10:25:51 AM com.jme.system.PropertiesIO <init>
INFO: PropertiesIO created
Aug 18, 2008 10:25:51 AM com.jme.system.PropertiesIO load
INFO: Read properties
Aug 18, 2008 10:25:51 AM com.jme.app.BaseSimpleGame initSystem
INFO: jME version 1.0
Aug 18, 2008 10:25:51 AM com.jme.input.joystick.DummyJoystickInput <init>
INFO: Joystick support is disabled
Aug 18, 2008 10:25:51 AM com.jme.system.lwjgl.LWJGLDisplaySystem <init>
INFO: LWJGL Display System created.
Aug 18, 2008 10:25:51 AM com.jme.renderer.lwjgl.LWJGLRenderer <init>
INFO: LWJGLRenderer created. W: 640H: 480
Aug 18, 2008 10:25:52 AM com.jme.app.BaseSimpleGame initSystem
INFO: Running on: ialmrnt5
Driver version: 6.14.10.4363
Starting to convert .obj to .jme
Intel - Intel 915GM - 1.4.0 - Build 4.14.10.4363
Aug 18, 2008 10:25:52 AM com.jme.renderer.AbstractCamera <init>
INFO: Camera created.
Aug 18, 2008 10:25:52 AM com.jme.util.lwjgl.LWJGLTimer <init>
INFO: Timer resolution: 1000 ticks per second
Aug 18, 2008 10:25:52 AM com.jme.scene.Node <init>
INFO: Node created.
Aug 18, 2008 10:25:52 AM com.jme.scene.Node <init>
INFO: Node created.
Aug 18, 2008 10:25:52 AM com.jme.scene.Node attachChild
INFO: Child (FPS label) attached to this node (FPS node)
Aug 18, 2008 10:25:52 AM class universityTutorials.TestObjJmeWrite start()
SEVERE: Exception in game loop
java.lang.NullPointerException
at universityTutorials.TestObjJmeWrite.simpleInitGame(TestObjJmeWrite.java:38)
at com.jme.app.BaseSimpleGame.initGame(Unknown Source)
at com.jme.app.BaseGame.start(Unknown Source)
at universityTutorials.TestObjJmeWrite.main(TestObjJmeWrite.java:25)
Aug 18, 2008 10:25:52 AM com.jme.app.BaseSimpleGame cleanup
INFO: Cleaning up resources.
Aug 18, 2008 10:25:52 AM com.jme.app.BaseGame start
INFO: Application ending.
Can anyone tell me how I might fix this? A black screen appears like it will show the model and than the application just stops.
I just fixed this error. The files were not in the project folder correctly. Fixing the file path solves this issue.