Vishwanath Deshmukh
Vishwanath Deshmukh

Reputation: 649

How to put texture in .obj file while using libgdx libs for android?

How to add texture in .obj file from .mtl file because libgdx can't render .mtl file.

Upvotes: 3

Views: 2524

Answers (1)

JB.
JB.

Reputation: 1110

Two problems there :

  • You cannot exploit .mtl yet (june 2012) in libgdx.
  • .obj format does not include textures (textures are described in the .mtl file).

But the solution is to ignore completely the MTL file and manually add your texture when you load your model.

sample code :

public load3dModel( String objfile, String texfile )
{
   ModelLoaderHints hint = new ModelLoaderHints(false);             
   m_mesh = ModelLoaderRegistry.loadStillModel(Gdx.files.internal(objfile), hint);
   Texture texture = new Texture(Gdx.files.internal(texfile), Format.RGBA4444, false);
   Material mat = new Material("mat",
                               new TextureAttribute(texture, 0, "u_Texture"));
   m_mesh.setMaterial(mat);
   ...

Upvotes: 3

Related Questions