XMLtoBinary

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.

There have been a few changes recently. Does it still not work? If so, I’ll look at it. It’s probably a small fix to binary->jme converter to write some parameter as the correct type.

Thanks. I figured out what the problem was. The XML file I was using was generated, but had no texture coordinates.


            <texturecoords data="NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN" >
            </texturecoords>
            <texturecoords texindex="1" data="" >
            </texturecoords>



That line was causing the ClassCastException

Another XMLtoBinary problem:



I thought I could load a model out of the .xml format, which works pretty good beside that the boundings of my model aren’t rotated.



Could somone tell what I’m doing wrong?



A picture can be found here

Bounding volumes may not be exporting correctly. I’ll look into it.