Importing from 3D File Formats
Learn to import and use OBJ and MTL format files to create objects in Three.js.
We'll cover the following...
We listed a number of formats that are supported by Three.js. We’ll quickly walk through a few examples of those formats.
The OBJ and MTL formats
OBJ and MTL are companion formats often used together. An OBJ file defines the geometry, and an MTL file defines the materials that are used. Both OBJ and MTL are text-based formats. A part of an OBJ file looks like this:
An MTL file defines materials, as follows:
The OBJ and MTL formats are well supported by Three.js, so this is a good format to choose if we want to exchange 3D models. Three.js has two different loaders we can use. If we only want to load the geometry, we use OBJLoader. The following screenshot shows this example:
Example: Load OBJ
Let’s execute the load-obj.js example in the below playground by clicking the “Run” ...