How to use the MTLLoader function from three

Find comprehensive JavaScript three.MTLLoader code examples handpicked from public code repositorys.

three.MTLLoader is a class in the Three.js library that allows loading and parsing of Wavefront OBJ files and their associated MTL material files.

85
86
87
88
89
90
91
92
93
94
    scene.add(line);
  }
}

function loadObject(data, index) {
  new THREE.MTLLoader(manager)
    .setPath('/assets/reconstruction/models/' + data.poses[index].class_name + '/')
    .load('textured.mtl', function(materials) {
      materials.preload();
      new THREE.OBJLoader(manager)
fork icon51
star icon209
watch icon21

73
74
75
76
77
78
79
80
81
    return a;
}

function addObjects(){
   
    //var mtlLoader = new THREE.MTLLoader();
    //mtlLoader.load("/static/r1.mtl", function(materials){

        //materials.preload();
fork icon26
star icon28
watch icon0

+ 2 other calls in file

How does three.MTLLoader work?

The MTLLoader class in the Three.js library is used to load Material Template Library (MTL) files, which describe the material properties of 3D models, and parse them into usable data for Three.js. When called, it will read the contents of an MTL file, parse the data, and return it in a format that Three.js can use to apply textures and other visual properties to 3D models.

65
66
67
68
69
70
71
72
73
74
}



var objLoader = new THREE.OBJLoader();
var mtlLoader = new THREE.MTLLoader();
var textureLoader = new THREE.TextureLoader();


// stonebird teach me how to use require
fork icon5
star icon23
watch icon3

+ 2 other calls in file

1373
1374
1375
1376
1377
1378
1379
1380
1381
1382


	return OBJLoader;


} )();


exports.MTLLoader = THREE.MTLLoader;
exports.OBJLoader = THREE.OBJLoader;
fork icon3
star icon6
watch icon1

+ 56 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import * as THREE from "three";
import { MTLLoader } from "three/examples/jsm/loaders/MTLLoader.js";
import { OBJLoader } from "three/examples/jsm/loaders/OBJLoader.js";

const mtlLoader = new MTLLoader();
mtlLoader.load("model.mtl", (materials) => {
  materials.preload();

  const objLoader = new OBJLoader();
  objLoader.setMaterials(materials);
  objLoader.load("model.obj", (object) => {
    scene.add(object);
  });
});

In this example, MTLLoader is used to load the materials defined in the model.mtl file. Once the materials are loaded, they are passed to OBJLoader, which is then used to load the 3D object defined in the model.obj file. Finally, the loaded object is added to the scene.

17
18
19
20
21
22
23
24
25
26
27
  THREE.Cache.enabled = true;
}


// TODO: Eventually include these only if they are needed by a component.
require('three/examples/js/loaders/OBJLoader');  // THREE.OBJLoader
require('three/examples/js/loaders/MTLLoader');  // THREE.MTLLoader
require('three/examples/js/BlendCharacter');  // THREE.BlendCharacter
require('three/examples/js/loaders/ColladaLoader');  // THREE.ColladaLoader
require('../../vendor/VRControls');  // THREE.VRControls
require('../../vendor/VREffect');  // THREE.VREffect
fork icon0
star icon0
watch icon0

+ 7 other calls in file

17
18
19
20
21
22
23
24
25
26
27
  THREE.Cache.enabled = true;
}


// TODO: Eventually include these only if they are needed by a component.
require('../../node_modules/three/examples/js/loaders/OBJLoader');  // THREE.OBJLoader
require('../../node_modules/three/examples/js/loaders/MTLLoader');  // THREE.MTLLoader
require('../../node_modules/three/examples/js/loaders/ColladaLoader');  // THREE.ColladaLoader
require('../../node_modules/three/examples/js/controls/VRControls');  // THREE.VRControls
require('../../node_modules/three/examples/js/effects/VREffect');  // THREE.VREffect

fork icon0
star icon0
watch icon0

+ 3 other calls in file

22
23
24
25
26
27
28
29
30
31
    return loader.load(urls)
  }
})()
const objLoader = new THREE.OBJLoader()
objLoader.loadP = jsUtil.promifyFn(objLoader.load.bind(objLoader), 1, 'rsv')
const mtlLoader = new THREE.MTLLoader()
mtlLoader.crossOrigin = true
mtlLoader.loadP = jsUtil.promifyFn(mtlLoader.load.bind(mtlLoader), 1, 'rsv')
const radiants = degrees => Math.PI / 180 * degrees
const { innerWidth: WIDTH, innerHeight: HEIGHT } = window
fork icon0
star icon0
watch icon4

+ 2 other calls in file

Other functions in three

Sorted by popularity

function icon

three.Vector3 is the most popular function in three (22341 examples)