# MTLLoader Not Working

**URL:** <https://discourse.threejs.org/t/mtlloader-not-working/5660>\
**Category:** Questions\
**Tags:** mtl-loader\
**Created:** [January 8, 2019, 9:01pm UTC](https://discourse.threejs.org/t/mtlloader-not-working/5660 "2019-01-08T21:01:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![andul007](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@andul007](https://discourse.threejs.org/u/andul007)\
**Post date:** [January 8, 2019, 9:01pm UTC](https://discourse.threejs.org/t/mtlloader-not-working/5660/1 "2019-01-08T21:01:26Z")

</div>

Hi,

I created a model with blender. I was successfully able to export the corresponding obj into my Three JS canvas.

Now I’m working on loading the MTL file from my Blender Export.

The weird thing is that for like a split second, it successfully displays the model with the textures applied appropriately on my Three js canvas, and then it suddenly crashes and errors.

This is the error:

```auto
TypeError: Cannot set property 'value' of undefined

initMaterial

node_modules/three/build/three.module.js:16198
16195 |   
16196 | if (material.lights) {  
16197 | // wire up the material to this renderer's lighting state> 
16198 | uniforms.ambientLightColor.value = lights.state.ambient;        
| ^ 16199 | uniforms.directionalLights.value = lights.state.directional;  
16200 | uniforms.spotLights.value = lights.state.spot;  
16201 | uniforms.rectAreaLights.value = lights.state.rectArea;

```

I am working in **_React JS_** so my code might look a little wonky, but here it is:

```auto
var mtlLoader = new MTLLoader();
        mtlLoader.load( mtl, material => {
                material.preload();
                var loader = new this.THREE.OBJLoader();
                loader.setMaterials( material );
                loader.load( obj,
                    object => {
                        console.log("entered into the stage");
                        this.treeHead = object;
                        this.treeHead.position.y += 30;
                        this.scene.add(this.treeHead);
                        this.start()

                    },
                    xhr => {console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );},
                    error => {console.log("Error! ", error);}
                );
            },
            xhr => {},
            error => {}
        );

```

I don’t really understand why its working for only half a second and then crashing.  
Your help would be much appreciated!

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [January 8, 2019, 10:17pm UTC](https://discourse.threejs.org/t/mtlloader-not-working/5660/2 "2019-01-08T22:17:13Z")

</div>

Have you tried to export to model to `glTF` instead? It’s the recommended 3D format of the project and a better choice than OBJ. More information about `glTF` and the respective Blender importer/exporter right here:

[https://threejs.org/docs/index.html#manual/en/introduction/Loading-3D-models](https://threejs.org/docs/index.html#manual/en/introduction/Loading-3D-models)

---

<div class="post-metadata">

**Author:** ![andul007](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@andul007](https://discourse.threejs.org/u/andul007)\
**Post date:** [January 9, 2019, 1:30am UTC](https://discourse.threejs.org/t/mtlloader-not-working/5660/3 "2019-01-09T01:30:24Z")

</div>

Ok I got the gLTF loader to work. My issue now is that for some reason its not exporting any of the materials. The model has no color and appears to be black. How would I go about fixing this?

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [January 9, 2019, 8:10am UTC](https://discourse.threejs.org/t/mtlloader-not-working/5660/4 "2019-01-09T08:10:26Z")

</div>

Have you added any lights to your scene?

Besides, you can always verify whether or not your `glTF` asset works by using one of the following viewers.

[https://gltf-viewer.donmccurdy.com/](https://gltf-viewer.donmccurdy.com/)  
[https://sandbox.babylonjs.com/](https://sandbox.babylonjs.com/)

---

<div class="post-metadata">

**Author:** ![andul007](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@andul007](https://discourse.threejs.org/u/andul007)\
**Post date:** [January 9, 2019, 4:25pm UTC](https://discourse.threejs.org/t/mtlloader-not-working/5660/5 "2019-01-09T16:25:58Z")

</div>

Yes I added an ambient light and three point lights. I see that there is lighting because the model has reflections but it’s still black.

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [January 9, 2019, 6:42pm UTC](https://discourse.threejs.org/t/mtlloader-not-working/5660/6 "2019-01-09T18:42:01Z")

</div>

Does the model work in the linked viewers?

---

<div class="post-metadata">

**Author:** ![andul007](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@andul007](https://discourse.threejs.org/u/andul007)\
**Post date:** [January 9, 2019, 7:29pm UTC](https://discourse.threejs.org/t/mtlloader-not-working/5660/7 "2019-01-09T19:29:32Z")

</div>

Yes they work. They just don’t have any shading / color. They’re all black.

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [January 9, 2019, 8:23pm UTC](https://discourse.threejs.org/t/mtlloader-not-working/5660/8 "2019-01-09T20:23:58Z")

</div>

Your issue might be a duplicate of this one:

> <https://stackoverflow.com/questions/53344348/how-to-use-gltf-loader-in-three-js-texture-and-material-displaying-as-black>

---

<div class="post-metadata">

**Author:** ![steveh](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@steveh](https://discourse.threejs.org/u/steveh)\
**Post date:** [January 3, 2020, 3:37am UTC](https://discourse.threejs.org/t/mtlloader-not-working/5660/9 "2020-01-03T03:37:02Z")

</div>

After hours of trying to use MTLLoader and OBJLoader with the code below and it not working I finally solved the issue.

If you are running IIS, ensure you have MIME type entries for both .mtl and .obj files. Set these to application/octet-stream.

I hope this will prevent a lot of pain for others.

The code I finally got to work was

```
function LoadOBJ()
	{
	  var mtlLoader = new THREE.MTLLoader();
	  mtlLoader.setResourcePath("") ;
	  mtlLoader.setPath("");
	  mtlLoader.load("cube.mtl", function(materials){
	  materials.preload();

      var objLoader = new THREE.OBJLoader();
      objLoader.setMaterials(materials);
      objLoader.setPath("");
	  objLoader.load("cube.obj",
	  
	        function(object)
			 {
			    console.log("Adding Object");
			    //track.add(object);
				track = object;
				track.position.set(0,0,0);
				scene.add(track);
			 }
		);	
	  });
	  
	 
	}
```

---

<div class="post-metadata">

**Author:** ![Ugochukwu\_Chime](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/ugochukwu_chime/32/63682_2.png) [@Ugochukwu\_Chime](https://discourse.threejs.org/u/Ugochukwu_Chime)\
**Post date:** [October 6, 2025, 3:59pm UTC](https://discourse.threejs.org/t/mtlloader-not-working/5660/10 "2025-10-06T15:59:25Z")

</div>

Didn’t see it here, and this was the solution for me. Sometimes Tr 1.000 in the mtl file tells three.js to display it with 100% transparency.

(aka invisible)
