Problem loading obj models

I have been playing with the obj2jme and tried to load a obj model. I have loaded the model but I cant see any textures with the model.

I have tried other models which dont have any texture, and they load OK, but when they have a texture, the texture doesnt load.



I have also tried 3ds model as well but it seems that there is a problem with loading textures. Does anybody know what is the problem. :frowning:

tomcat

I think you need to load the texture manually using a TextureState.



DP

Did you specify the material library setting? obj files are split into two parts. Do you get any warnings loading it? Send your jme to XML and print it out. Where is it looking for texture files from?

I set the material library settings as in the tutorial. I used almost the same code for testing.


Send your jme to XML and print it out. Where is it looking for texture files from?



Will email you code and the model in a few minutes.
tomcat

emailed the code now.

tomcat

You can also convert it into jme’s format, load it with my editer, add the texture, and then save it to the final file. If you want to add additional files right click select add, on the tree,select Spiral then Mesh. Then answer NO to the question.



To add a Texture right click on a spiral select TextureState form the state add list. Then you Right click on the TextureState and select add texture.

I don’t believe .tif is supported with jME. That may explain why you can’t see the texture? At least, Image loading of .tif files returns null for me in TextureManager.

Badmi wrote:


You can also convert it into jme’s format, load it with my editer, add the texture


Thx, I'll have a play with it and see if I can load my model into it.

Cep21 wrote:
I don't believe .tif is supported with jME

This may sound simplistic, but will it work if I convert the images to .jpg or .gif?
tomcat

I tried and it does. But you see lines in the texture because it’s not square so you’d have to square it when you save. And the material state in the file is very dark so you have to change that. But it works.

I converted the file and loaded it but couldnt see the texture. I must be doing something wrong :? What changes did you make?

tomcat

Try turning off lights and you’ll see it. Inside the mtl file you have



Ka 0.000000 0.000000 0.000000

Kd 0.000000 0.000000 0.000000

Ks 0.000000 0.000000 0.000000

Ns 0.000000



So it creates a material state with no ambient,diffuse, specular color at all. That’s why you can’t see it with lights. You should just remove that from the file.

Cep21,



I have tried this:


newmtl hum_body
illum 4
Ka 0.000000 0.000000 0.000000
Kd 0.913725 0.866667 0.800000
Ks 0.913725 0.866667 0.800000
Ns 0.000000
map_Kd newbird.jpg

as well as:
newmtl hum_body
illum 4
map_Kd newbird.jpg

I have even added a point light to the scene. Still no luck. I see the bird as grey as it ever was. No idea whats happening.
tomcat

Badmi wrote:


You can also convert it into jme’s format, load it with my editer, add the texture, and then save it to the final file. If you want to add additional files right click select add, on the tree,select Spiral then Mesh. Then answer NO to the question.


Thx, I have tried to use the editer, but it doesnt run. Seems the jar is missing some files (!)
tomcat

For me it seems as the .obj - loader doesn’t load it’s textures from where i expect it to.



Lets assume i have an .obj in /home/xxx/projects/myJmeTest/resources with corresponding .mtl and .jpg files where the .mtl file references the .jpg file with only filename and not a path (i think this is common usage and means that the .jpg is in the same directory as the .mtl).



If i use the example from cep21’s famous starter guide then the texture (.jpg) is not found because it is not searched in /home/xxx/projects/myJmeTest/resources but in /home/xxx/projects by default which is the base-directory the classloader uses.



If i give myJmeTest/resources/???.jpg in the .mtl then the .jpg is found and the loader works like a charm.



i’m on linux btw



regards

martin

The loader works on InputStream, not File or URL or String. Streams have no idea of where they come from. Because of this, users have the option of specifying a texture URL with the loader. .jme files have no idea they came from .obj files. This makes it more customizable. I was able to load tomcat’s obj file with my own code.



Want to load texture? Just specify a texture directory.



Texture isn’t loading? Just look at the XML and see where it’s looking for the texture.

Ok, but how do i specify the texture directory ?



The only way i found was in the .mtl - file

( or putting the texture file where the loader looks for it)

and that would mean one cannot use .mtl - files as they are but has to edit them.



Maybe i’m overlooking someting here but if not then a property for the texture directory besides the one for the .mtl file would be fine ( or defaulting to the same place the .mtl file is)



If you could include a texture into the .obj example (maggie) from the starter guide then things should become clear for me.

Look at the example for loading ms3d files or md2 files, and look at the javadoc for setProperty of JmeBinaryReader

Sorry can’t verify this here at work.



Do i understand this right as:

Ignore the “texture file not found” when converting .obj and .mtl to .jme

and only when loading the resulting .jme binary file, set the texture-dir property for the JmeBinaryReader ?



sorry for my bad english btw.

You should get no texture file not found converting from .obj to .jme



Set a texture directory when loading .jme

Ok i have peharps found where is my problem but i don’t know if it’s my fault (i don’t use jme has it must be used or if it’s due to a jme bug so please be patient with me :slight_smile: i’m a newbie with jme)



if i change this in AseToJme.java



public void setTexture(Texture t) {
                            if (texture.length==0) texture=new Texture[1];
                            texture[0] = t;
 }



become :


in public void setTexture(Texture t) {
                            if (texture == null || texture.length==0) texture=new Texture[1];
                            texture[0] = t;
                        }


i can convert ase with no problem

if in TextureState.java i changed the method like that :

/**
*
* <code>setTexture</code> sets a single texture to the first
* texture unit.
* @param texture the texture to set.
*/
public void setTexture(Texture texture) {
if (this.texture != null) {
this.texture[0] = texture;
} else {
this.texture = new Texture[1];
this.texture[0] = texture;
}
resetFirstLast();
}

/**
 *
 * &lt;code&gt;getTexture&lt;/code&gt; gets the texture that is assigned to the
 * first texture unit.
 * @return the texture in the first texture unit.
 */
public Texture getTexture() {
    if (texture != null) {
        return texture[0];
    } else {
        return null;
    }
}

[/code}

and i can convert 3ds with texture and obj with texture with no more problem.

I’m quite lost, don’t know jme enough to see if it’s my fault or a bug

thanks for help,

adenthar[code]

/**

*

  • <code>setTexture</code> sets a single texture to the first
  • texture unit.
  • @param texture the texture to set.

    */

    public void setTexture(Texture texture) {

    if (this.texture != null) {

    this.texture[0] = texture;

    } else {

    this.texture = new Texture[1];

    this.texture[0] = texture;

    }

    resetFirstLast();

    }



    /**

    *
  • <code>getTexture</code> gets the texture that is assigned to the
  • first texture unit.
  • @return the texture in the first texture unit.

    */

    public Texture getTexture() {

    if (texture != null) {

    return texture[0];

    } else {

    return null;

    }

    }

    [/code}



    and i can convert 3ds with texture and obj with texture with no more problem.



    I’m quite lost, don’t know jme enough to see if it’s my fault or a bug



    thanks for help,



    adenthar