Texturing an object

hello all



id like to ask a question i think all of you might laugh at me at please -



im making a project - a car racing game. I currently have a 3d max 7 developed model, exported it to an .obj type, and have loaded it into a window. its all very simple, but the problem i have is that the .mtl created by 3d max doesnt seem to be loading the textures onto the model at rendertime (or runtime, whichever is correct!)



i used the obj loader in the testchooser to load my model. when using the maggie.obj and maggie.mtl, it will load both object and textures. But when i use my model, it will only load my model but not the corresponding textures.



This has really confused me, as I dont understand why it would work for maggie but not for my model.



So my question is - is there a reason that the textures will not load onto my model, and a sub question is - would it be better off to load each texutre seperately and then apply it onto the model at runtime, instead of trying to do it all at compiletime?



thank you for any help

mtm :slight_smile:

I haven't managed to get models exported as .obj files with textures running in jME either. Exporting and loading the models as .3ds however worked well. Might be an alternative.


i tired in .3ds too, but that also didnt work! what code did you use - the one from jmetest, or did you develop your own?

thanks
mtm :)

I'm using the .3ds model loader provided by jME from the current CVS version. I don't know if that's relevant, but there may have been any significant changes to it since 0.9 if you're running that version.

As far as I remember the texture file path was a absolute one in the .3ds file. By replacing it with a relative one, in my case simply with the file name (and putting the texture file in the same directory), I got the texture to load.

hmmm



could you post the code for the loader you have, as my cvs agent is currently playing up (im trying to set up connections to two different cvs servers!)



thanks in advance

mtm

might not be the same thing but I get .obj to load in mw3d2 I usually have to assign textures in the editor though but the uv/s are respected I never really use the mtl files however you should note that maggie uses vertex colors not texture images, might be the key to solving your problems

you need to specify the texture location

public static Node loadOBJModel(String modelName, String bound) {
      Node model = null;
      URL modelLoc = MainFoosballGame.class.getClassLoader().getResource(
            "Models/" + modelName);
      FormatConverter converter = new ObjToJme();
           converter.setProperty("mtllib", modelLoc);
      ByteArrayOutputStream BO = new ByteArrayOutputStream();
      JmeBinaryReader jbr = new JmeBinaryReader();
         *jbr.setProperty("texurl", modelLoc);
      try {
         converter.convert(modelLoc.openStream(), BO);
         jbr.setProperty("bound", bound);
         model = jbr.loadBinaryFormat(new ByteArrayInputStream(BO
               .toByteArray()));
      } catch (IOException e) { // Just in case anything happens
         System.out.println("Damn exceptions!" + e);
         e.printStackTrace();
         System.exit(0);
      }
      return model;
   }


I put asterik next to line missing in maggie model loading example. the reason maggie loads w/o this line is she has no texture file just a material.
mud2005 said:

you need to specify the texture location

public static Node loadOBJModel(String modelName, String bound) {
      Node model = null;
      URL modelLoc = MainFoosballGame.class.getClassLoader().getResource(
            "Models/" + modelName);
      FormatConverter converter = new ObjToJme();
           converter.setProperty("mtllib", modelLoc);
      ByteArrayOutputStream BO = new ByteArrayOutputStream();
      JmeBinaryReader jbr = new JmeBinaryReader();
         *jbr.setProperty("texurl", modelLoc);
      try {
         converter.convert(modelLoc.openStream(), BO);
         jbr.setProperty("bound", bound);
         model = jbr.loadBinaryFormat(new ByteArrayInputStream(BO
               .toByteArray()));
      } catch (IOException e) { // Just in case anything happens
         System.out.println("Damn exceptions!" + e);
         e.printStackTrace();
         System.exit(0);
      }
      return model;
   }


I put asterik next to line missing in maggie model loading example. the reason maggie loads w/o this line is she has no texture file just a material.




already tried this, but it still wont work. thats very strange. thanks for the info regarding maggie.mtl, i didnt realise that, it makes more sense now.

should i just use texturemanager to load the textures and then assign them? it seems more straightforward, but i dont know if its practical.

thanks
mtm :)

righto

im getting a Could not load image ... URL was null error and an UNtextured model into the loader - does this mean its tried to load images corresponding to the model but could not?

the model still loads fine, just no textures and im using a URL type to specify where the model is located. Do i need to define two url's - one for model, one for textures?


hmmm

im quite surprized that didnt work for you, couple of things:

of course make absolute sure your texture is in same folder as your .obj and .mtl file

also look in your mtl and make sure this line is correct at end of file

map_Kd bballTex.bmp


my texture in this case is named bballTex.bmp. I have to change this manually when I use wings3d as it always puts diffuse.bmp there and I never name my texture diffuse.bmp

#
newmtl fskin
Ka  0.5 0.5 0.5
Kd  0.5 0.5 0.5
Ks  1.0 1.0 1.0
d  1.0
Ns  0.1
illum 2
map_Kd fskin.jpg
#
# EOF





thats what my mtl file is. it does say the right image name at the bottom. however, there doesnt seem to be much (all textures are loaded from different parts of one jpg file) - im not sure if thats because theres only one file, or because its not doing something it should be.

ok post your .obj loading code, and im not sure what u mean by this:

(all textures are loaded from different parts of one jpg file)


edit: also make sure you have right class name here:

URL model=***HelloModelLoading***.class.getClassLoader().getResource("xx.obj");

Mud


(all textures are loaded from different parts of one jpg file)

see the image jmelatestsrcjmetestdatamodeldrfreak.jpg

quick update - i managed to get the object textured (to a very basic level) using a texture manager, its seemed to do the trick

ill post my code once ive got a fully textured model.

thanks!
mtm :)