Forum: 3D Modeling


Subject: Making a .mtl file.?

jedswindells opened this issue on Aug 09, 2009 · 5 posts


CaptainJack1 posted Mon, 10 August 2009 at 8:38 AM

If you want to make a material file for your OBJ, it's pretty simple. Both the OBJ and MTL files are plain text, and you can edit them with any good text editor. There's some good information on the OBJ and MTL file formats at www.wotsit.org, but here's the basics:

In your OBJ file, you need to add a line that looks like this:

mtllib FileName.mtl

Most export programs that create the file for you use the same name for the OBJ file and the MTL file. You'll put your materials in the MTL file. Still in your OBJ file, you need to add a line that looks like this:

usemtl MaterialName

above the faces that use that material. it's pretty common to have one material per group, and the "usemtl" line usually appears right after the group identifier, which is a line that starts with just the letter "g".

Your MTL file might look like this:

newmtl MaterialName
Ns 100.0
d 1.0
illum 2
Kd 1.0 1.0 1.0
Ka 1.0 1.0 1.0
Ks 1.0 1.0 1.0

The "newmtl" command identifies the material, and any program that can read the MTL file will mathc the name identified on that line with the name used in the OBJ file on the usemtl line.

In this example, "Ns" is the specular highlight percentage, "d" is a dissolve ratio designed to fade materials from one to the other across a polygon, "illum" refers to the illumination model, which I don't think any current program actually uses, "Kd" is the diffuse color (color is RGB, spearated by spaces, with values from zero to one), "Ka"  is the ambient color, and "Ks" is the specular color.

You can specify a texture map for the colors with the command map_Kd (and map_Ka, map_Ks, and so on) and a file name. There are lots of other commands to, but you can find them in the MTL spec at the web site above, if you're interested.

Note that there may be features in the MTL spec that your rendering program doesn't use, so you may have to experiment. As mentioned before, it's usually best to lay your materials down in the rendering program, and not try to export them from the modeler.