Appying textures to each of object's faces?

Allright… I’m on pls.help.me frenzy tonight, so I’ve decided to ask for help in this part of help board as well!



Could you guys tell me how to apply texture to each face of an object?

Let’s say I have imported box object from 3d modeling program and now I want to put one texture on each of it’s faces, to get something similar to this:





I tried for a while and I’m tired now really >.<

Help?

:puppy_eyes:

Your options:

  • Combine your textures into one in photoshop and make UV-mapping in 3dMax/Maya/Blender/etc to correspond to each face.
  • Assemble a box out of eight six quads and apply a texture to each quad (you use the skybox as an example on how this is done)
  • Calculate UV coodrinates manually and use multi texturing (worst option: not all the cards will support 6 textures at the same time, and you will require alot of math to pull this one off).

yeah, you should really go for the first option lex mentions. most modelling programs have automatic mesh unwrapping to fit a texture on a complete mesh making it easy…other ways of doing it will just give you hell when you want to do similar stuff to other geometries…

Yeh, noticed that 3ds max does mesh unwrapping automatically, so, all I should do now is export this object and load texture onto it and that texture will be wrapped automatically?

I'm importing .obj with 3d studio max, when putting texture on it it still doesnt work as it should (texture is repeated on every face of the box).

>.<

Could any of you guys post a simple sample program that would load obj,mtl and texture file and then display it correctly? Please :slight_smile:

Because I think I'm missing something here :confused:





Cheers!

You could use the cube re-mapper that is floating around in the wiki/forums… This has been asked before several times. The problem is that each of your faces in the box has exactly the same texture coordinates.



Of course if you change this exactly in the modeling program, then it would not be a prob.

So if I understood correctly it is enough to put obj, mtl and texture file in one place, load it up with Jmonkey and it will put texture on it without need to use all those texture states? : o

Pretty much yes… specially if you import the model with all ResourceLocatorTool paths with the right values, and later you export the imported model as jME so that next time it is trivial to do!  :wink:

Whenever I read "trival" and "jme" in one line I start to shiver :(.

At this moment after putting obj, mtl and texture files into same folder, importing object, setting textdir and mtlib properties I'm getting white object without any texture on it, not even "missing texture" :s

If you have any more advices I'll be grateful.



-goes to bed-

Two comments, you should try using the ModelLoader as it creates the jme file for you, and if you liked how it looked there, then when you load that jme file (instead of the obj or 3ds or whatever), it will look like that.



White objects are usually related to forgetting calling updateRenderState or lack of lighting.



Good luck

Alright, I'm having my obj, mtl and texture in one folder.

When I load OBJ this way:


   public  Spatial loadOBJModel (String modelFile, Node objNode){
   Spatial         loadedModel   = null;
   FormatConverter      formatConverter = null;      
   ByteArrayOutputStream    BO       = new ByteArrayOutputStream();       
   String         modelBinary   = modelFile;   
        URL         modelURL   = ModelLoader.class.getClassLoader().getResource(modelBinary);
      
   
        FormatConverter converter=new ObjToJme();
        converter.setProperty("mtlib",modelURL);
        converter.setProperty("txtdir",modelURL);
   BO=new ByteArrayOutputStream();
        System.out.println(modelURL);

       try {
            converter.convert(modelURL.openStream(), BO);
            loadedModel=(Spatial)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
       } catch (IOException ex) {
            ex.printStackTrace();
       }
        
       loadedModel.setModelBound(new BoundingBox());
       loadedModel.updateModelBound();

       objNode.attachChild(loadedModel);
       objNode.updateRenderState();
       setMyNode(objNode);
       return loadedModel;
}


Object is loaded but white.



When I try loading it this way however:


   public void  setMyNode(Node obj)
{
    myNode = obj;
    myNode.getWorldBound();
    myNode.updateWorldBound();
}

  public static Spatial loadModel (String modelFile){
   Spatial         loadedModel   = null;
   FormatConverter      formatConverter = null;      
   ByteArrayOutputStream    BO       = new ByteArrayOutputStream();       
   String         modelBinary   = modelFile;   
        URL         modelURL   = ModelLoader.class.getClassLoader().getResource(modelBinary);
      
   
        FormatConverter converter=new ObjToJme();
        converter.setProperty("mtlib",modelURL);
        converter.setProperty("txtdir",modelURL);
    BO=new ByteArrayOutputStream();
         System.out.println(modelURL);
        try {
            converter.convert(modelURL.openStream(), BO);
            loadedModel=(Spatial)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
        } catch (IOException ex) {
            ex.printStackTrace();
        }        
       return loadedModel;
}

  public void Insert (String model,String mapfile,Node objNode){
        Spatial     teksturowany = null;
        TextureState Tstate      = null;
        Node        iNode        = null;
    
        teksturowany = loadModel(model);
        teksturowany.setModelBound(new BoundingBox());
        teksturowany.updateModelBound();
       

        objNode.attachChild(teksturowany);
        Tstate = display.getRenderer().createTextureState();
       
   
        Texture tekstura=TextureManager.loadTexture(Main.class.getClassLoader().getResource(mapfile),Texture.MM_LINEAR,Texture.FM_LINEAR);
     
      
        Tstate.setTexture(tekstura);
       
        teksturowany.setRenderState(Tstate);
    
        setMyNode(objNode);
    }


I'm getting material covered with texture but with incorrect unwrap~ settings.


Sorry for constant spam with nob questions guys and thanks for help I really appreciate it!

@Duenez: I'm considering using jme files later, atm I change imported objects very often and it's more handy for me to use obj's instead.

Is the unwrap incorrect in that it's turned upside down? That could be because jME seems different from most other engines and tools in how it defines the texture coordinate U axis. Try adding the "flip" argument to the textures you load, or mirror texture U before you export, and see if it improves things.

Nope, texture is entierly repeated on each of faces as if there were no unwrap settings at all >.<

lex said:

- Combine your textures into one in photoshop and make UV-mapping in 3dMax/Maya/Blender/etc to correspond to each face.

Have you tried that yet? I can't see how anything could go wrong with that.

I have tried that too, I'll post texture and obj file later since I'm at school atm :slight_smile:



Cheers!

I had a little helpfull "talk" with Morq and he gave me the final

tip to solve the/my "texture repeated on each of faces"-problem

disc. above so I try a little update here.



I tried three common ways of texturing in 3DStudio max:


  1. simple planar UVW texturing

      (using UVW mapping modifier)
  2. edit/map UVWs from a multitexture image to the spec faces

      (using UVW mapping modifier and UVW unwrap modifier)
  3. texturing by using the material editor and cropping



    => Texturing from export file will be imported correct to jME

        if method 1 or 2 was used.

        In case of method 3 the complete texture image will be

        repeated on each of faces.