Loading a .jme model problems

I have had a good search around and can't seem to find an answer to this, but sorry if i just missed it.



I have the .jme file exported from monkeyworld3D version 3. Now as I understand it, this is a jmonkey native model format. I am trying to import this model as the level for a game. All the examples I have found are either out of date (using the jme binary importer (that the right one?) and not the binary importer) or are concerned with converting other model formats to jme first.



I have tried quite a few things to just import my .jme model, but nothing is working.



Can anyone show me how to do this? Possibly just what would need to be changed in the hellomodelloading example file if instead of using the model.obj file it was a model.jme file? or any other example code you like to show this.

Simply loading the new binary format should work like this.



Node node = (Node)BinaryImporter.getInstance().load(inputStream); // inputstream for the model in the jme binary format

Loading it as a Spatial is probably smarter as it won't always be a Node.

Thank you both.



Used Gaheris's code, it now runs but doesn't display anything. It gives these errors:


java.io.IOException: Not in GZIP format
   at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:132)
   at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
   at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)
   at com.jme.util.export.binary.BinaryImporter.load(Unknown Source)
   at HelloModelLoadingMine.simpleInitGame(HelloModelLoadingMine.java:84)
   at com.jme.app.BaseSimpleGame.initGame(Unknown Source)
   at com.jme.app.BaseGame.start(Unknown Source)
   at HelloModelLoadingMine.main(HelloModelLoadingMine.java:68)



Here is my current code, I am think I am doing something wrong with putting the .jme file into an inputstream:
(this is just a modified hellomodelloading example)



import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;

import com.jme.app.AbstractGame;
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingSphere;
import com.jme.scene.Node;
import com.jme.util.LoggingSystem;
import com.jme.util.export.binary.BinaryImporter;
import com.jmex.model.XMLparser.Converters.FormatConverter;
import com.jmex.model.XMLparser.Converters.ObjToJme;

import com.jme.util.BinaryFileReader;
import java.io.InputStream;
import java.io.FileInputStream;

public class HelloModelLoadingMine extends SimpleGame {
    public static void main(String[] args) {
        HelloModelLoadingMine app = new HelloModelLoadingMine();
        app.setDialogBehaviour(AbstractGame.ALWAYS_SHOW_PROPS_DIALOG);
        // Turn the logger off so we can see the XML later on
        LoggingSystem.getLogger().setLevel(Level.OFF);
        app.start();
    }

    protected void simpleInitGame() {
        // Point to a URL of my model
        //URL model=HelloModelLoadingMine.class.getClassLoader().getResource("jmetest/data/model/level1.jme");
        File model = new File("//Applications/jme/jme/data/model/level1.jme");
        FileInputStream FIS = null;
      try {
         FIS = new FileInputStream(model);
      } catch (FileNotFoundException e1) {
         // TODO Auto-generated catch block
         e1.printStackTrace();
      }
        Node node = null;
      try {
         node = (Node)BinaryImporter.getInstance().load(FIS);
      } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } // inputstream for the model in the jme binary format
        rootNode.attachChild(node);
    }
}



And renanse: I'm not sure how to load it as a Spatial.
TheBob said:

And renanse: I'm not sure how to load it as a Spatial.


I'd assume he meant casting it to a Spatial instead of a Node.

oh ok.

 protected void simpleInitGame() {
           // Point to a URL of my model
          // URL model= ModelLoader.class.getClassLoader().getResource("C:/workspace/Nile/level/nile.jme");
      
       File f = new File("C:/workspace/Nile/level/nile.jme");
           FileInputStream FIS = null;
         try {
            FIS = new FileInputStream(f);
         } catch (FileNotFoundException e1) {
            
            e1.printStackTrace();
         }
          
           try {             
                         
              Spatial level =(Spatial)BinaryImporter.getInstance().load(FIS);
               // shrink this baby down some
              level.setLocalScale(.1f);
               level.setModelBound(new BoundingSphere());
               level.updateModelBound();
               // Put her on the scene graph
               rootNode.attachChild(level);
              
           } catch (IOException e) {   // Just in case anything happens
               System.out.println("Damn exceptions!" + e);
               e.printStackTrace();
               System.exit(0);
           }
          
          
       }



...
INFO: Timer resolution: 1000 ticks per second
25.12.2006 14:11:37 com.jme.scene.Node <init>
INFO: Node created.
25.12.2006 14:11:37 com.jme.scene.Node <init>
INFO: Node created.
25.12.2006 14:11:37 com.jme.scene.Node attachChild
INFO: Child (FPS label) attached to this node (FPS node)
java.io.IOException: Not in GZIP format
at java.util.zip.GZIPInputStream.readHeader(Unknown Source)
at java.util.zip.GZIPInputStream.<init>(Unknown Source)
at java.util.zip.GZIPInputStream.<init>(Unknown Source)
at com.jme.util.export.binary.BinaryImporter.load(Unknown Source)
at com.jme.util.export.binary.BinaryImporter.load(Unknown Source)
at example.HelloWorld.simpleInitGame(HelloWorld.java:40)
at com.jme.app.BaseSimpleGame.initGame(Unknown Source)
at com.jme.app.BaseGame.start(Unknown Source)
at example.HelloWorld.main(HelloWorld.java:23)

whats wrong?
i have to add that i haven`t a tutorial to load a jme level, but for every other format? why?

Although this Thread is kind of old, I am using this, since I have the same Problem.



I guess the problem is, that the .jme file is not in GZIP format and thus the map won't be loaded at all.

Doess the export function of MW3D not export the map into a valid .jme format?

Or is there a way to convert the .jme file into a GZIP formated .jme file?



EDIT:

Apparently the old .jme (JmeBinaryWrite) format is not compatible with the new .jme (BinaryImporter) format. So is there anyway to convert the older into the new one, or do we have to wait untill MW3D exports with the new Exporter (in case that really is the reason that it doens't work).

easy, just execute the following commands:

gzip -s .jme myLevel.jme


How to do this on linux:
open shell
type in command
How to do this in windows:
go to website opensuse.org
click download
download iso's
md5 iso's
burn iso's
put first cd in drive
reboot
install opensuse
boot opensuse
configure opensuse
open shell
type command

That's why I like linux: 2 steps vs 11 steps.

Offtopic: Man, you just made my day!  XD

draGy said:

So is there anyway to convert the older into the new one, or do we have to wait untill MW3D exports with the new Exporter (in case that really is the reason that it doens't work).

It probably is the reason, and you can certainly convert.
Just load the old format using JmeBinaryReader, there are tutorials on the wiki on how to do that (just skip the part where it loads 3ds or obj, and go right for the part involving JmeBinaryReader).
Then you can save the same scene using BinaryExporter, and voila, scene converted!

Be aware that because the old format is deprecated, it is possible you may run into a feature support issue or two.