1
$\begingroup$

How to make a .mtl file from .obj file ? I just have the obj file of a Open quick haptics and i cant work with it without the mtl file,

$\endgroup$

3 Answers 3

1
$\begingroup$

Well, when I export mesh to OBJ format, it also creates an MTL file.

Google said that:

MTL file is an auxiliary file containing definitions of materials that may be accessed by an OBJ file.

If possible, you need to Import to Blender and then Export to OBJ. MTL file will be generated automatically.

$\endgroup$
1
$\begingroup$

You can try this:

  1. Open your obj file with a text editor
  2. Remove any reference to materials in the first lines
  3. Remove any reference to materials in the last lines
  4. Look for the faces definition section, a face looks like this:

f 6/4/1 3/5/3 7/6/5 ...

Three numbers for each vertex (position coord./texture coord./normal vector) – find a way to delete the texture number so it looks like this:

f 6//1 3//3 7//5 ...

Here is an example, an obj file from a blender file with only the default cube:

# Blender v2.80 (sub 74) OBJ File: ''
# www.blender.org
mtllib untitled.mtl
o Cube
v 1.000000 1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 1.000000 1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 1.000000 -1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 1.000000
v -1.000000 -1.000000 1.000000
vt 0.375000 0.000000
vt 0.625000 0.000000
vt 0.625000 0.250000
vt 0.375000 0.250000
vt 0.375000 0.250000
vt 0.625000 0.250000
vt 0.625000 0.500000
vt 0.375000 0.500000
vt 0.625000 0.750000
vt 0.375000 0.750000
vt 0.625000 0.750000
vt 0.625000 1.000000
vt 0.375000 1.000000
vt 0.125000 0.500000
vt 0.375000 0.500000
vt 0.375000 0.750000
vt 0.125000 0.750000
vt 0.625000 0.500000
vt 0.875000 0.500000
vt 0.875000 0.750000
vn 0.0000 1.0000 0.0000
vn 0.0000 0.0000 1.0000
vn -1.0000 0.0000 0.0000
vn 0.0000 -1.0000 0.0000
vn 1.0000 0.0000 0.0000
vn 0.0000 0.0000 -1.0000
usemtl Material
s off
f 1/1/1 5/2/1 7/3/1 3/4/1
f 4/5/2 3/6/2 7/7/2 8/8/2
f 8/8/3 7/7/3 5/9/3 6/10/3
f 6/10/4 2/11/4 4/12/4 8/13/4
f 2/14/5 1/15/5 3/16/5 4/17/5
f 6/18/6 5/19/6 1/20/6 2/11/6

Here is the same file edited:

# Blender v2.80 (sub 74) OBJ File: ''
# www.blender.org
o Cube
v 1.000000 1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 1.000000 1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 1.000000 -1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 1.000000
v -1.000000 -1.000000 1.000000
vn 0.0000 1.0000 0.0000
vn 0.0000 0.0000 1.0000
vn -1.0000 0.0000 0.0000
vn 0.0000 -1.0000 0.0000
vn 1.0000 0.0000 0.0000
vn 0.0000 0.0000 -1.0000
s off
f 1/1/1 5/2/1 7/3/1 3/4/1
f 4/5/2 3/6/2 7/7/2 8/8/2
f 8/8/3 7/7/3 5/9/3 6/10/3
f 6/10/4 2/11/4 4/12/4 8/13/4
f 2/14/5 1/15/5 3/16/5 4/17/5
f 6/18/6 5/19/6 1/20/6 2/11/6

Then you can add the textures in blender and export it again as obj, the material file is created automatically.

$\endgroup$
1
  • $\begingroup$ The file editing isn't necessary, Blender can import the file just fine even if the .mtl is missing. Exporting the object results in a creation of a new .mtl anyway. $\endgroup$
    – Robert Gützkow
    Jul 23, 2019 at 21:06
0
$\begingroup$

A .mtl file contains information about the shader settings and linked textures. It gets automatically created when you export a file. The .obj file contains information like vertex positions, faces, uv mapping. Basically the 3D representation of the meshes. You cannot convert one from the other, as they contains different data sets. You could however import the .obj into Blender and then assign your own textures (or maybe you can find the original ones somewhere). The shader settings are very basic and you would need to change them either way, as it would, for example not import as a principled bsdf for instance. Depending on the shaders complexity, some features wouldnt even port properly if you had the .mtl...

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .