Model Loading Times

Hi everyone,

I have been using jME 1.0. I had some code that loaded my .obj files (using ObjToJme). It worked perfectly and loading each model relatively quickly.



I just recently updated my jME version to 2.0 and now my loading times have went waaaay up. Each model takes about 4 seconds to loading, where before I could load all 80 or so models in less than 6 seconds.  Is there a new way to load obj files and convert them to .jme? Here is the code I am using:

Spatial gamemap;
      BinaryImporter importer = BinaryImporter.getInstance();

      URL modelURL = getClass().getClassLoader().getResource(
            "models/" + filename + ".obj");
      FormatConverter converter = new ObjToJme(); // com.jmex.model.XMLparser.Converters.*
      URL materialLocation = getClass().getClassLoader().getResource(
            "models/Card.mtl");
      URL textureLocation = getClass().getClassLoader().getResource(
            "models/cards/" + cardLocation + "/card_texture.jpg");

      if (materialLocation == null)
         Logger.getLogger("FIRSTLogger").log(Level.SEVERE,
               "Material not found");
      if (textureLocation == null)
         Logger.getLogger("FIRSTLogger").log(Level.SEVERE,
               "Texture not found");
      converter.setProperty("mtllib", materialLocation);
      converter.setProperty("texdir", textureLocation);

      ByteArrayOutputStream BO = new ByteArrayOutputStream();
      try {
         converter.convert(modelURL.openStream(), BO);
         
         
         gamemap = (Spatial) importer.load(new ByteArrayInputStream(BO
               .toByteArray()));
         gamemap.setCullHint(Spatial.CullHint.Never);
         gamemap.setModelBound(new BoundingBox());
         gamemap.updateRenderState();
         gamemap.updateModelBound();
         gamemap.setName("EntityModel");
         return gamemap;
      } catch (IOException e) {
         e.printStackTrace();
      }
      
      throw new RuntimeException("Card " + cardLocation + " couldn't be loaded");



EDIT: I've also noticed that all the textures for the models seem a bit blurred. I'm thinking these problems might be somehow related, no?

Do you see Texture not found messages on the console output?

Adding ResourceLocators to point to the correct directory could help then eventually.

Yes, I do see the warning messages. I've always seen those and have tried to get rid of them, but couldn't figure out how. They didn't seem to slow down loading times before, but maybe they are this time around.



Could you give me any hints on what to do with the ResourceLocator as you say?



EDIT: I've figured out how to do as you say:

      try{
         ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE,
               new SimpleResourceLocator(textureLocation));
      }
      catch(Exception e){
         e.printStackTrace();
      }



It got rid of the warnings, but didn't speed up loading times. The following is what I get from the console.


Jul 18, 2009 10:31:52 AM com.jme.scene.Node <init>
INFO: Node created.
Jul 18, 2009 10:31:52 AM com.jme.util.geom.GeometryTool minimizeVerts
INFO: mesh: temp0 (com.jme.scene.TriMesh) old: 160 new: 104
Jul 18, 2009 10:31:52 AM com.jme.scene.Node attachChild
INFO: Child (temp0) attached to this node (obj file)


Looking through the source for jME, I have found that the time consumer is:
TextureManager.loadTexture(this, key); in Texture.class
So, it seems Core-Dump is onto something.

OK, I've narrowed the problem down entirely.



It seems that the texture I specified is a .jpg. The TextureManager.loadImage method tries to get a loader for the texture, but it always returns null (ImageLoader loader = loaders.get(fileExt.toLowerCase()):wink:



It then goes down to use a generic loader:

java.awt.Image image = ImageIO.read(stream); // readImage(fileExt, stream);

                imageData = loadImage(image, flipped);



The problem, as to be expected, is in reading the pixels. The for loop takes awhile.



So, my question is, what do I have to do to speed this up? Was this algorithm changed, or was .jpg support lost or something?

JPG support hasn't been lost, AFAIK, it has always just used existing code in the JRE to convert them as JPEG is a bitch of a format to convert - I think sun use an external C library for the job (or at least they used to).



It could possibly be a JRE issue tho - Have you changed JRE recently (especially up to 6) as I think these libraries are changing as part of the "open sourceing" of java, and proprietary libraries are being replaced (such as the com.sun.* packages) - it could be related? 



Might be worth trying to run against an earlier JRE.



Alternatively, convert your imagery to another format. JPEG isnt widely used as a game graphics format - generally a non lossy format is preferred.


Thanks JOC. I have converted my textures to tga and it works fine now! I believe the problem was something with the jre I was using. I didn't test it, but I had actually downgraded to java 5 from 6 (to make it mac compatible). So, in all regards you were right I believe.



THANKS EVERYONE!