Textures won't load

Hello,



I'm loading several obj models, all goes well but the textures do not load. in the folder in which i placed the obj files are also the mtl files and a folder which contains the textures.

I also created a java package from which the code loads the model. (models/container.obj in the code below :slight_smile: )





This is the code im using to load a model:



public class LoadContainer extends SimpleGame {



        private static final Logger logger = Logger

            .getLogger(LoadContainer.class.getName());





public static void main(String[] args)

        {

        LoadContainer app = new LoadContainer();

        app.setConfigShowMode(ConfigShowMode.AlwaysShow);

        app.start();

        }



        @Override

        protected void simpleInitGame()

        {

        // Point to a URL of the model

        URL model=ModelInladen.class.getClassLoader().getResource("models/container.obj");





        // Create something to convert .obj format to .jme

        FormatConverter converter=new ObjToJme();



        // Point the converter to where it will find the .mtl file from

        converter.setProperty("mtllib",model);





        // This byte array will hold the .jme files

        ByteArrayOutputStream BO=new ByteArrayOutputStream();

        try {

            // Use the format converter to convert .obj to .jme

            converter.convert(model.openStream(), BO);







            Node Container=(Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));





            // shrink the model

            Container.setLocalScale(.1f);

            Container.setModelBound(new BoundingSphere());

            Container.updateModelBound();













            // Put the model on the scene graph

            rootNode.attachChild(Container);



        }



                        catch (IOException e) {  // Just in case anything happens

            logger.logp(Level.SEVERE, this.getClass().toString(),

                    "simpleInitGame()", "Exception", e);

            System.exit(0);

        }



Am i missing something which is supposed to load the textures?

<< same problem here >>





Sbook
Also check that the mtl file is using a relative filepath to get to the texture


but dunno how to check that. If someone can tell me how to do that, it would be really appreciated.
Thanks for your help

As far as I know, the textures you put on a model in a modeling program don’t get imported into JME.

You instead load the textures separately and apply them to the model.



For a basic example, look here:

http://www.jmonkeyengine.com/wiki/doku.php/creating_your_first_app_with_simplegame

Thank you for your advice… though are you sure that works for a model? As it does not seem to have any effect if i try it that way… (could be doing something wrong though  :P)

As far as I know, the textures you put on a model in a modeling program don't get imported into JME.


Of course that can be loaded automatically. In case of .obj there is (should) always a coresponding .mtl file describing what texture to load and how to map it. It is a text-file so you can open it (as the .obj file as well) with a texteditor. Have a look on the texture-file name and its directory.

Having a look in ObjToJme-Converter-Class show following:

* Converts .obj files into .jme binary format. In order for ObjToJme to find
* the .mtl library, you must specify the "mtllib" tag to the baseURL where the
* mtl libraries are to be found: eg.
* setProperty("mtllib",new File("c:/my material dir/").toURL());
*
* Textures will be loaded from the directory indicated in the model unless you
* specify a directory to load them from via setting a property: eg.
* setProperty("texdir", new File("c:/my texdir/").toURL());


So try to set the texdir-property as well....

If this is not working as well try to set the ResourceLocator to your tex-directory:

        try {
         ResourceLocatorTool.addResourceLocator(
                 ResourceLocatorTool.TYPE_TEXTURE,
                 new SimpleResourceLocator(Utils.class.getClassLoader().getResource(
                               "YOUR DIR")));
      } catch (URISyntaxException e) {
         e.printStackTrace();
      }



YOUR DIR in your case might be "models/"

Hope that helps.

thank you ttrocha!

This might be a stupid question but… how do i get into that ObjToJme class? i see it in the library… but how do i get to the code?  ://

Actually I don't know how you installed jME and what IDE you use. I got it from Subversion and checked out the whole sourcecode. Actually I think that in the downloadable jars the sourcecode is already included.



Another way is to use googlecode's codebrowser-option:

http://code.google.com/p/jmonkeyengine/source/browse/trunk/src/com/jmex/model/converters/ObjToJme.java