Importing obj/mtl with textures

I've just written my very first jME program today, so it's entirely possible this is user error.  If so, hopefully someone can tell me what I'm doing wrong.  And if not, what's the recommended way of reporting bugs?



I'm trying to import an OBJ file whose textures are described in an MTL file.  Material properties are getting imported correctly, but the image maps are not.  I won't quote the OBJ file here, since it's quite large, but here is the MTL file:





#Produced by Art of Illusion 2.3 beta, Sat May 13 12:03:07 PDT 2006

newmtl Base

Kd 0.8 0.656 0.44

Ks 0 0 0

Ka 0 0 0

illum 1

newmtl Untitled_1

Kd 1 1 1

map_Kd mushroom1.jpg

Ks 1 1 1

map_Ks mushroom3.jpg

Ka 0 0 0

illum 2

Ns 129





This may be a red herring, but I noticed a possible problem in the XML that gets written to the console when I import it:





                        <texturestate >

                                <texture file=" mushroom1.jpg" texnum="0" wrap="3" >

                                </texture>

                        </texturestate>





Could that extra space at the beginning of the filename be causing the problems?



Thanks!



Peter

Peter, have You tried to import Your model with jmetest.renderer.loader.TestObjJmeWrite from the jme standard tests ?

If You still have this issue then maybe You can upload Your model somewhere for us to have a look.



err, and is this a misspelling in Your user name ?


I'm new to jME too (i.e. this is post #1), having lots of fun so far but got snagged up on using Blender with jME. I ran into the same thing the other day - the extra space in the filename makes the texture file not load. ObjToJme.java adds the extra space to the filename:


263:           t.setImageLocation("file:/" + s.trim().substring(6));


Should just be substring(7) and/or another trim() at the end if it's parsing a line like "map_Kd thetexture.jpg".

Another thing that took some extra time to figure out was that ObjToJme needs normals which are not exported by default in Blender's .obj exporter, but now I'm happy again.

I can't confirm this.

I tried out a simple textured cube exported from AOI and loaded with jmetest.renderer.loader.TestObjJmeWrite which works fine here.

But i used todays nightly build so maybe You should upgrade and try again.

Beware that most external adds (jme-physics and the like) will most likely not compile against this atm.

Thanks!  I took a look at the source code for TestObjJmeWrite, and figured out how to make it work.  I had copied my obj loading code from one of the tutorials, but it was missing one important line (presumably because the object in the tutorial didn't have an image map):



jbr.setProperty("texurl", model);



where model is the URL for the obj file.  With that addition, I now have a speckled mushroom!



There seems to be a lot of boilerplate code involved in importing models, which could be eliminated by a few utility methods.  For example, I don't see any reason you couldn't do the entire import with a single line:



node = ObjToJme.import(objURL);



or, in the rare cases where the obj, mtl, and texture files weren't all in the same directory,



node = ObjToJme.import(objURL, mtlURL);



The various setProperty() calls could also be eliminated by providing reasonable default behavior (that is, assume everything is in the same directory, which is usually the case).


winkman said:

err, and is this a misspelling in Your user name ?


Oops!  Thanks for pointing that out.  I don't suppose there's a way to change it?

Peter

Glad to help and to welcome THE peastman over here  :wink:



I agree with Your suggested utility methods, but think that there simply wasn't enough demand and/or time for our ever busy dev's to add such.

Of course Your'e welcome to add what You come up with to the usercode or drop a request at the suggestions->features section.



… and looks like You were able to change Your user name.

eh… i showed up too late. what was his user name? :slight_smile:

Just a minor typo sfera, i just asked because i suspected him to be peastman from the aoi forums.

You found me out!  It's hard to hide in such a small world.  :wink:



Being new to this community, I wasn't sure what the preferred way was to submit feature requests, bug reports, code, etc.  I'll see what I can put together and post it over there.



Peter

I tried running TestObjJmeWrite with a .obj file exported from Art of Illusion and got a NullPointException at line 67. This is where the conversion from .obj to .jme takes place.



Any suggestions?  :?


line 67 where? in TestObjJmeWrite line 67 is empty: http://www.student.cs.uwaterloo.ca/~eworosho/showsrc.php?src=jmetest.renderer.loader.TestObjJmeWrite.java

if you mean line 66 of TestObjJmeWrite, then the model was not found in the classpath.

Thanks! Now I'm getting this error after resolving the classpath:





java.lang.ClassCastException: com.jme.scene.TriMesh cannot be cast to com.jme.scene.Node

at jmetest.renderer.loader.TestObjJmeWrite.simpleInitGame(TestObjJmeWrite.java:71)

Depends on what model You are loading.

If it consists of more than one object then You get a node containing the objects

If it's only one object then You get a trimesh.



You can cast both cases to spatial or know what You will get and use that without cast