[Solved] JME Loading problem

Im stuck, I created a 3ds model, i loaded it using ModelLoader utility, it loads up fine and converts it to jme, no problems. I even reopened it in the LoadModel utility as a .jme loads fine.

Now when i load it in my program it sits there for about 2 mins, gives me a warning saying it cant find the texture but it then displays the model in the program with the texture just fine. It just takes over two mins to load it. So i think it must be a problem with the JME so i reopen it in ModelLoader instantly, so i think it must have something to do with it not displaying the texture. From what i know though is that the 3ds/jme file has its texture marked in it and finds the location from it, if it was exported from like 3Ds Max with the texture.

Now to start off i have src and data which is on the same level and set using the Java Build Path and adding them on there. Using this MutiformatLocator inside a Method in initSystem()

try {
           MultiFormatResourceLocator loc = new MultiFormatResourceLocator(ResourceLocatorTool.class.getResource(""), ".jpg", ".png", ".tga");
           ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, loc);
       } catch (URISyntaxException e) {
       try {
           MultiFormatResourceLocator loc2 = new MultiFormatResourceLocator(ResourceLocatorTool.class.getResource(""), ".3ds");
           ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_MODEL, loc2);
       } catch (URISyntaxException e) {

The terrain gets textures fine using inside a buildTerrain():

ProceduralTextureGenerator pt = new ProceduralTextureGenerator(heightMap);
      pt.addTexture(new ImageIcon(ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "/images/terrain/dirt.png")), -128, 0, 128);
      pt.addTexture(new ImageIcon(ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "/images/terrain/grass.png")), 0, 128, 255);
      pt.addTexture(new ImageIcon(ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "/images/terrain/snow.png")), 128, 255, 384);

/images/ect ect are within the data folder and load fine

same with the skybox

but it dies out on the buildPlayer model:

private void buildPlayer() {       
        //Load Model
        URL model = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_MODEL, "/models/fighter1.jme");
        try {

            BinaryImporter binaryImporter = new BinaryImporter(); // Used to convert the jme usable file to a Node
            InputStream fileInput = null;
            Node plane = (Node)binaryImporter.load(fileInput); //importer returns a Loadable, cast to Node
         // scale model to maximum extent of 5.0
            plane.updateGeometricState( 0, true );
            BoundingVolume worldBound = plane.getWorldBound();
            if ( worldBound == null ) {
               plane.setModelBound( new BoundingBox() );
               plane.updateGeometricState( 0, true );
                worldBound = plane.getWorldBound();
            if ( worldBound != null ) // check not still null (no geoms)
                Vector3f center = worldBound.getCenter();
                BoundingBox boundingBox = new BoundingBox( center, 0, 0, 0 );
                boundingBox.mergeLocal( worldBound );
                Vector3f extent = boundingBox.getExtent( null );
                float maxExtent = Math.max( Math.max( extent.x, extent.y ), extent.z );
                if ( maxExtent != 0 ) {
                    Node scaledModel = new Node( "scaled model" );
                    scaledModel.attachChild( plane );
                    scaledModel.setLocalScale( 5.0f / maxExtent );
                    plane = scaledModel;
            // shrink this baby down some    
            plane.setLocalRotation( new Quaternion().fromAngleAxis( - FastMath.PI/2, new Vector3f(1,0,0)) );
            player = new Node("Player Node");
            player.setLocalTranslation(new Vector3f(100,0, 100));
            // Put her on the scene graph
        } catch (IOException e) {   // Just in case anything happens
            System.out.println("Damn exceptions!" + e);


it gets the model with:
URL model = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_MODEL, "/models/fighter1.jme");

converts it into a input stream
InputStream fileInput = null;

then sits out here at the binary importer for over two mins
Node plane = (Node)binaryImporter.load(fileInput);
com.jme.util.resource.ResourceLocatorTool locateResource
WARNING: Unable to locate: /C:/Documents and Settings/...removedForSpace.../models/FIGHTER.TGA

my guess it has to do with the /C:/ becouse thats where the texture is located
so maybe its looking for it? then timing out?
after a few mins it continues on and loads the model fine with texture.
I pulled most of the loader from ModelLoader since it works fine there.

anyone with any ideas?

The MultiFormatResourceLocator first tries to append all kind of extensions to your filename and searches them.

Its useful if you just want to load an "earth" texture, but don't care if its earth.jpg or earth.png etc …

If nothing is found it tries the original name you provided, which would be the correct one in your case.


just noticed you could set setTrySpecifiedFormatFirst(true) on MultiFormatResourceLocator, so it would first search your provided filename+extension.

Better use SimpleResourceLocator if you know what kind of file you want to load.

First set up the path (notice the slash at the end):

        new SimpleResourceLocator(Start.class.getClassLoader().getResource("data/textures/")));

And load the file using the locater (just the filename is enough):

URL textureUrl = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "texturename.png");

The locators are also stripping off directories from the head and repeatedly checking at each level.  I wonder if the file existence check takes a long time to resolve?

Ok first i tried the setTrySpecifiedFormatFirst(true) but it did not speed anything up.

But changing it to the SimpleResourceLocator worked great thanks!

If you could find time to run the slow version through a profiler, that would be very helpful!

Hate to show my ignorance but what profile are you taking about?

I would be glad to if you tell me how

Basically a profiler runs your code and shows you where things are going slowly.  YourKit is a good one, Netbeans IDE has one built in too.

Im using Eclipse, looks like one has to pay for YourKit, anyone know of a good free one?

From this thread

If you are developing an open-source project you can also apply for a free open-source license from YourKit

Eclipses TPTP seems veerrryyyy slow when trying to profile a jME application.

At least i couldn't set ip up correctly yet.

Tell you the truth I never made heads or tails of it myself… but perhaps others are smarter, hence the link

Ok i found the problem

The problem is in getBaseFileName of the multiformatResourcelocator

private String getBaseFileName(String resourceName)
      File f = new File(resourceName);
      String name = f.getPath();
      int dot = name.lastIndexOf('.');
      if (dot < 0)
         return resourceName;
         return resourceName.substring(0, dot);

the problem occurs when your resourceName starts with a /  for example /C:/Documents and Settings/......
f.getPath() will remove the leading /. this will result in resourceName.substring(0,dot) being 1 character to short.

For me the class that calls this method with such a path is TextureKey.read().

replacing resourceName.substring  with name.subString  works for me but i get the feeling he is searching to long because he will just keep shortening the resourceName until you finally end up with just the filename and no path.

The searching by trimming down is the intended functionality.  The other part though should be fixed.  Taking care of it.

i figured it had to do with the leading / but i could not figure out how to remove it

My .jme model loads properly, and includes the texture, but it still gives me this warning (even though the texture obviously works fine)

WARNING: Unable to locate: /C:/src/com/file.tga