I've made my object in 3DS Max and exported it out as a triangular mesh. I've then used the 'template code' from the wiki to try to load the .obj and it's still not working.
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.jme.app.AbstractGame;
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingSphere;
import com.jme.scene.Node;
import com.jme.util.export.binary.BinaryImporter;
import com.jmex.model.converters.FormatConverter;
import com.jmex.model.converters.ObjToJme;
/**
* Started Date: Jul 22, 2004<br><br>
*
* Demonstrates loading formats.
*
* @author Jack Lindamood
*/
public class LoadingObj extends SimpleGame {
private static final Logger logger = Logger
.getLogger(LoadingObj.class.getName());
public static void main(String[] args) {
LoadingObj app = new LoadingObj();
app.setDialogBehaviour(AbstractGame.ALWAYS_SHOW_PROPS_DIALOG);
// Turn the logger off so we can see the XML later on
app.start();
}
protected void simpleInitGame() {
// Point to a URL of my model
URL model=LoadingObj.class.getClassLoader().getResource("jmetest/data/model/teapot.obj");
// Create something to convert .obj format to .jme
FormatConverter converter=new ObjToJme();
// Point the converter to where it will find the .mtl file from
converter.setProperty("mtllib",model);
// This byte array will hold my .jme file
ByteArrayOutputStream BO=new ByteArrayOutputStream();
try {
// Use the format converter to convert .obj to .jme
converter.convert(model.openStream(), BO);
Node maggie=(Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
// shrink this baby down some
maggie.setLocalScale(.1f);
maggie.setModelBound(new BoundingSphere());
maggie.updateModelBound();
// Put her on the scene graph
rootNode.attachChild(maggie);
} catch (IOException e) { // Just in case anything happens
logger.logp(Level.SEVERE, this.getClass().toString(),
"simpleInitGame()", "Exception", e);
System.exit(0);
}
}
}
I do not know why it's not working, I'm using Eclipse IDE and it doesn't have any errors... But I'm new to jME and just at least want to get an object on the screen that I've created and it seems like I cannot.
What am I doing wrong?
What happens is when I go to load the model it gets to the jME screen and then just 'crashes'...
Nov 25, 2007 6:18:28 PM com.jme.app.BaseGame start
INFO: Application started.
Nov 25, 2007 6:18:28 PM com.jme.system.PropertiesIO <init>
INFO: PropertiesIO created
Nov 25, 2007 6:18:28 PM com.jme.system.PropertiesIO load
INFO: Read properties
Nov 25, 2007 6:18:30 PM com.jme.input.joystick.DummyJoystickInput <init>
INFO: Joystick support is disabled
Nov 25, 2007 6:18:30 PM com.jme.system.lwjgl.LWJGLDisplaySystem <init>
INFO: LWJGL Display System created.
Nov 25, 2007 6:18:31 PM com.jme.system.lwjgl.LWJGLDisplaySystem getValidDisplayMode
INFO: Selected DisplayMode: 800 x 600 x 32 @60Hz
Nov 25, 2007 6:18:31 PM com.jme.system.PropertiesIO save
INFO: Saved properties
Nov 25, 2007 6:18:31 PM com.jme.app.BaseSimpleGame initSystem
INFO: jME version 1.0
Nov 25, 2007 6:18:31 PM com.jme.renderer.lwjgl.LWJGLRenderer <init>
INFO: LWJGLRenderer created. W: 800H: 600
Nov 25, 2007 6:18:31 PM com.jme.app.BaseSimpleGame initSystem
INFO: Running on: ati2dvag
Driver version: 6.14.10.6727
ATI Technologies Inc. - Radeon X1300/X1550 Series x86/SSE2 - 2.0.6956 WinXP Release
Nov 25, 2007 6:18:31 PM com.jme.renderer.AbstractCamera <init>
INFO: Camera created.
Nov 25, 2007 6:18:31 PM com.jme.util.lwjgl.LWJGLTimer <init>
INFO: Timer resolution: 1000 ticks per second
Nov 25, 2007 6:18:31 PM com.jme.scene.Node <init>
INFO: Node created.
Nov 25, 2007 6:18:32 PM com.jme.scene.Node <init>
INFO: Node created.
Nov 25, 2007 6:18:32 PM com.jme.scene.Node attachChild
INFO: Child (FPS label) attached to this node (FPS node)
Nov 25, 2007 6:18:32 PM com.jme.scene.Node <init>
INFO: Node created.
Nov 25, 2007 6:18:32 PM com.jme.util.geom.GeometryTool minimizeVerts
INFO: batch: temp0: Batch 0 old: 504 new: 376
Nov 25, 2007 6:18:32 PM com.jme.scene.Node attachChild
INFO: Child (temp0) attached to this node (obj file)
Nov 25, 2007 6:18:32 PM class LoadingObj start()
SEVERE: Exception in game loop
java.lang.ClassCastException: com.jme.scene.TriMesh cannot be cast to com.jme.scene.Node
at LoadingObj.simpleInitGame(LoadingObj.java:48)
at com.jme.app.BaseSimpleGame.initGame(BaseSimpleGame.java:503)
at com.jme.app.BaseGame.start(BaseGame.java:69)
at LoadingObj.main(LoadingObj.java:31)
Nov 25, 2007 6:18:32 PM com.jme.app.BaseSimpleGame cleanup
INFO: Cleaning up resources.
Nov 25, 2007 6:18:32 PM com.jme.app.BaseGame start
INFO: Application ending.
Also, am I supposed to be doing something else while trying to load this object? Am I supposed to make it a mesh, poly, patch in 3DS Max? Honest, need help here... I'm lost.
