frenchtoast747 / webgl-obj-loader

A simple OBJ model loader to help facilitate the learning of WebGL.
http://frenchtoast747.github.io/webgl-obj-loader/
MIT License
281 stars 59 forks source link

Support .mtl files #22

Closed frenchtoast747 closed 6 years ago

frenchtoast747 commented 9 years ago

Usually, when an .obj file is exported, a .mtl file is exported as well.

The .mtl contains information such as texture maps and colors. An .obj file will reference a lib name from which to load material names. The name of the lib is the name of the corresponding .mtl file to load. A material is then prefixed before one or more faces that use that material.

For example:

# at the top of SomeModel.obj file
mtllib SomeModel.mtl
# ...vertex, vertex normal, and texture coord definitions here...
usemtl my_material
f 2/1/1 4/2/2 3/3/3
f 5/4/4 7/5/5 6/6/6
...

While parsing, the material information should be associated with the specific faces. Several simple models that I have seen usually only have a single material that applies to all faces, although, this may not always be the case.

I'm not entirely sure how to handle application of MTL information to the OBJ model at the moment.

This addition could greatly help in getting models with simple textures loaded quickly in an organized manner.

Helpful reading materials: http://nendowingsmirai.yuku.com/forum/viewtopic/id/1723#.VEf6cPnF9wB http://people.cs.clemson.edu/~dhouse/courses/405/docs/brief-mtl-file-format.html https://en.wikipedia.org/wiki/Wavefront_.obj_file#Material_template_library

frenchtoast747 commented 6 years ago

This will be completed once mtl-support and mtl-support-v2 labeled issues are completed.