Using OBJMTLLoader with multiple materials

Three.js provides a number of standard geometries that you can use to create your 3D scenes. Complex models, however, are more easily created in dedicated 3D modeling applications such as Blender or 3ds Max. Luckily, though, Three.js has great support for a large number of export formats, so you can easily load models created in these kinds of packages. A standard that is widely supported is the OBJ format. With this format, the model is described with two different files: an .obj file that defines the geometries and an .mtl file that defines the material. In this recipe, we'll show you the steps you need to take to successfully load a model using OBJMTLLoader, which is provided by Three.js.

Getting ready ...

Get Three.js Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.