I modified the HelloModelLoading tutorial to try and make it load a model from an XML file using XMLtoBinary.
protected void simpleInitGame() {
// Point to a URL of my model
URL model = Test.class.getClassLoader().getResource("maggie.xml");
// 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();
// This will read the .jme format and convert it into a scene graph
JmeBinaryReader jbr = new JmeBinaryReader();
// Use this to visualize the .obj file in XML
BinaryToXML btx = new BinaryToXML();
//*********
//create converter
XMLtoBinary xtb = new XMLtoBinary();
try {
// Use the format converter to convert .obj to .jme
// converter.convert(model.openStream(), BO);
//*********
//convert XML file to jME binary
xtb.sendXMLtoBinary(model.openStream(), BO);
// Send the .jme binary to System.out as XML
btx.sendBinarytoXML(new ByteArrayInputStream(BO.toByteArray()), new OutputStreamWriter(
System.out));
// Tell the binary reader to use bounding boxes instead of
// bounding spheres
jbr.setProperty("bound", "box");
// Load the binary .jme format into a scene graph
Node maggie = jbr.loadBinaryFormat(new ByteArrayInputStream(BO.toByteArray()));
// shrink this baby down some
maggie.setLocalScale(.1f);
// Put her on the scene graph
rootNode.attachChild(maggie);
}
catch (IOException e) { // Just in case anything happens
System.out.println("Damn exceptions!" + e);
e.printStackTrace();
System.exit(0);
}
}
I copied the outputed XML to a file, then tried to make the model loader load that XML. This time around, it outputs the XML to the screen correctly, but bombs on a ClassCastException in the jME source.
java.lang.ClassCastException
at com.jme.scene.model.XMLparser.JmeBinaryReader.readBegining(Unknown Source)
at com.jme.scene.model.XMLparser.JmeBinaryReader.loadBinaryFormat(Unknown Source)
at com.jme.scene.model.XMLparser.JmeBinaryReader.loadBinaryFormat(Unknown Source)
at Test.simpleInitGame(Test.java:59)
at com.jme.app.SimpleGame.initGame(Unknown Source)
at com.jme.app.BaseGame.start(Unknown Source)
at Test.main(Test.java:30)
The line from my code that is line 59 is:
Node maggie = jbr.loadBinaryFormat(new ByteArrayInputStream(BO.toByteArray()));
Am I using this right? Or is this only intended to write to a file? It looks like it half works, because this line still works:
btx.sendBinarytoXML(new ByteArrayInputStream(BO.toByteArray()), new OutputStreamWriter(System.out));
Thanks.