ObjToJme -> IOEXception

Hi,



i have a strange problem: I try to load an .obj mesh an show it on a scene, using the following code:



    private void buildShip() {
        URL source = space.class.getClassLoader().getResource("spaceproject/mesh/firstShip.obj");
        URL sourceTex = space.class.getClassLoader().getResource("spaceproject/mesh/");
        loadObjMesh(source, sourceTex);
    }
   
   
    private void loadObjMesh(URL meshSource, URL texSource) { 
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjToJme conv = new ObjToJme();
                     conv.setProperty("mtllib",meshSource);
                     conv.convert(new BufferedInputStream(meshSource.openStream()), baos);
            JmeBinaryReader jbr = new JmeBinaryReader();
                            jbr.setProperty("bound","box");
                            jbr.setProperty("texurl", texSource);
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            ship = jbr.loadBinaryFormat(bais);
            //groesse skalieren
            ship.setLocalScale(.0025f);
            ship.setLocalTranslation(new Vector3f(100,0, 100));
            ship.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
        } catch (IOException e) {
            System.out.println("Exception: " + e);
            e.printStackTrace();
            System.exit(0);
        }
    }  



It compiles without any warnings or errors, but when I start the program, i get this exception:


Exceptions: java.io.IOException: Binary Header doesn't match.  Maybe wrong file?
java.io.IOException: Binary Header doesn't match.  Maybe wrong file?
        at com.jmex.model.XMLparser.JmeBinaryReader.readHeader(Unknown Source)
        at com.jmex.model.XMLparser.JmeBinaryReader.loadBinaryFormat(Unknown Source)
        at com.jmex.model.XMLparser.JmeBinaryReader.loadBinaryFormat(Unknown Source)
        at spaceproject.gameSurface.loadObjMesh(gameSurface.java:169)
        at spaceproject.gameSurface.buildShip(gameSurface.java:153)
        at spaceproject.gameSurface.initGame(gameSurface.java:130)
        at com.jme.app.BaseGame.start(Unknown Source)
        at spaceproject.Main.main(Main.java:28)



I am sure about the path (if i print out the buffer size of "baos" i get a proper value). I also tried different .obj/.mtl files: Some created by my own with wings3D, some downloaded from the internet.
Has anyone a suggestion, please?

ObjToJme converts the model to the new binary format, JmeBinaryReader is outdated. Use BinaryImport instead…



Example from FlagRush 7:



 
           MaxToJme C1 = new MaxToJme();
           ByteArrayOutputStream BO = new ByteArrayOutputStream();
            URL maxFile = Lesson7.class.getClassLoader().getResource("jmetest/data/model/bike.3ds");
            C1.convert(new BufferedInputStream(maxFile.openStream()),BO);
            model = (Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));

It works - thanks a lot  :smiley:

Thnx man… You're my hero…



I was lookin' information 2 days ago… but I got nothing… thnx a lot

@devs: maybe a @deprecated tag could help avoiding these problems (it seems to me people encounter this problem quite often)

Hm, went ahead and did that… even if people are still using that, it's no longer supported and could break at any time.

i noticed, thanks