Load model from Blender into JME

Hi,



i am trying to load a model that i made in blender into my game.

I followed these tutorials



I am using the following code to load the model


XMLImporter xmlImporter = new XMLImporter();
  Spatial base = null; // Where to dump mesh.
  URL url;
  url = Gameclass.class.getClassLoader().getResource("model/octagon-jme.xml");
  try {
    base = (Spatial) xmlImporter.load(url);
  } catch (Exception e) {
    throw new IllegalArgumentException(
          "Failed to load URL: " + url, e);
  }
  base.setModelBound(new BoundingBox());
  base.updateModelBound();
  rootNode.attackChild(base);



But i always get an IllegalArgumentException. I cant see what i've done wrong though :(

There are two things which can cause this problem, try this:

  1. A path like "model/octagon-jme.xml" will attempt to load from the package of the class, try putting "/" before the path to load from the root of the jar: "/model/octagon-jme.xml"
  2. Make sure that you have the package "model" in your source and that it contains the file "octagon-jme.xml".

If i add / in front of it, the url becomes null.

The file octagon-jme.xml does exist => /bin/model/octagon-jme.xml





If i try to load another model (3ds) i have a similiar setup, but this one works fine:


MaxToJme maxtojme = new MaxToJme(); // the converter
      Spatial base = null; // Where to dump mesh.
      // For loading the raw file
      ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();

      // File Path for the model (dump file in toplevel of classpath)
      // URL url = Main.class.getClassLoader().getResource(new
      // File(name)).toURI().toURL());
      URL url;
      url = Connections.class.getClassLoader().getResource("model/6eck.3ds");
      InputStream is = null;
      try {
         is = url.openStream();
      } catch (Exception err) {
         System.out.println("Could not open Model file: " + err);
      }
      try {

         // Converts the file into a jme usable file
         maxtojme.convert(is, bytearrayoutputstream);

         // Used to convert the jme usable file to a TriMesh
         BinaryImporter binaryImporter = new BinaryImporter();
         ByteArrayInputStream in = new ByteArrayInputStream(bytearrayoutputstream.toByteArray());

         // importer returns a Loadable, cast to Node
         base = (Spatial) binaryImporter.load(in);
      } catch (Exception err) {
         System.out.println("Error loading md3 model:" + err);
      }



I have also tried to export the model from bender to a 3ds file. Loading that one does not cause any exceptions, but the model seems to be not existant in the game (not visible at all :o)

For reference;

I just got this too, when i decided to 'extend' my Engine (jME) class, rather than instancing it. My ResourceLoader class and Engine class are in two different packages.

Don't know if it helps solving it, but it sounds related.



Edit: I don't know how you launch your app, but in my case it seems to be about something not being initialized properly/yet.

Are you using an IDE?  If you are using Eclipse, I have noticed that sometimes you have to manually refresh your resource directories if you have put new or updated items into it (I guess so that it shuffles them over to the bin directories) or else you'll get an error.  I don't know about NetBeans. 



If you are still having problems, paste the full error and maybe a snapshot (or faithful text ) of your project directories.

Thanks for your help :slight_smile:





I am using Eclipse.



I still could'nt get rid of the error.



Here is the exception:


Exception in game loop
java.lang.IllegalArgumentException: Failed to load URL: file:/D:/Programme/dev/eclipse/TestWorkspace/connections/bin/data/model/octagon-jme.xml
   at main.Gamestone.buildStone(Gamestone.java:72)
   at main.Gamestone.<init>(Gamestone.java:54)
   at gamestates.IngameState.setupEnvironment(IngameState.java:559)
   at gamestates.IngameState.<init>(IngameState.java:114)
   at handler.MenuHandler$EnterAction.performAction(MenuHandler.java:55)
   at com.jme.input.ActionTrigger.performAction(ActionTrigger.java:264)
   at com.jme.input.ActionTrigger$CommandTrigger.performAction(ActionTrigger.java:291)
   at com.jme.input.InputHandler.processTriggers(InputHandler.java:426)
   at com.jme.input.InputHandler.update(InputHandler.java:411)
   at gamestates.MenuState.stateUpdate(MenuState.java:119)
   at com.jmex.game.state.CameraGameStateDefaultCamera.update(CameraGameStateDefaultCamera.java:90)
   at com.jmex.game.state.GameStateNode.update(GameStateNode.java:71)
   at main.Connections.update(Connections.java:50)
   at com.jme.app.BaseGame.start(BaseGame.java:84)
   at main.Connections.main(Connections.java:156)
Caused by: java.io.IOException
   at com.jme.util.export.xml.DOMInputCapsule.readSavable(DOMInputCapsule.java:786)
   at com.jme.util.export.xml.XMLImporter.load(XMLImporter.java:95)
   at com.jme.util.export.xml.XMLImporter.load(XMLImporter.java:108)
   at main.Gamestone.buildStone(Gamestone.java:70)
   ... 14 more
Caused by: java.io.IOException
   at com.jme.util.export.xml.DOMInputCapsule.readSavableArrayList(DOMInputCapsule.java:960)
   at com.jme.scene.Node.read(Node.java:679)
   at com.jme.util.export.xml.DOMInputCapsule.readSavableFromCurrentElem(DOMInputCapsule.java:819)
   at com.jme.util.export.xml.DOMInputCapsule.readSavable(DOMInputCapsule.java:779)
   ... 17 more
Caused by: java.lang.NumberFormatException: For input string: ""
   at java.lang.NumberFormatException.forInputString(Unknown Source)
   at java.lang.Integer.parseInt(Unknown Source)
   at java.lang.Integer.parseInt(Unknown Source)
   at com.jme.util.export.xml.DOMInputCapsule.readSavableArrayList(DOMInputCapsule.java:947)
   ... 20 more



My Project structure can be seen here
main/connections.java is my main class which starts the game.
main/gamestone.java is the class that tries to load the model

ive put the model in /bin/data/model/octagon-jme.xml
(added the /data folder recently, and already updated the code)