# Obj Loader and materials

**URL:** <https://discourse.threejs.org/t/obj-loader-and-materials/34976>\
**Category:** Questions\
**Tags:** obj-loader, materials\
**Created:** [February 17, 2022, 4:57am UTC](https://discourse.threejs.org/t/obj-loader-and-materials/34976 "2022-02-17T04:57:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jackson33](https://avatars.discourse-cdn.com/v4/letter/j/87869e/32.png) [@Jackson33](https://discourse.threejs.org/u/Jackson33)\
**Post date:** [February 17, 2022, 4:57am UTC](https://discourse.threejs.org/t/obj-loader-and-materials/34976/1 "2022-02-17T04:57:28Z")

</div>

I am trying to add a material to an .obj file that I have and would like to add the MeshBasicMaterial to it but I am not able to find any information on it. This is what I have so far. It doesn’t work

loader.load(‘assets/tinker.obj’,function( object ){  
const material = new THREE.MeshBasicMaterial({  
color: 0xffff00  
});  
const mesh = new THREE.Mesh( object, material);  
object.scale.set(0.2,0.2,0.2);  
scene.add( mesh );  
},  
function( xhr ){  
console.log(( xhr.loaded / xhr.total \* 100) + ‘% 100’);  
},  
function( error ){  
console.log(‘An error happend’);  
}  
);

---

<div class="post-metadata">

**Author:** ![Chaser\_Code](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/chaser_code/32/20199_2.png) [@Chaser\_Code](https://discourse.threejs.org/u/Chaser_Code)\
**Post date:** [February 17, 2022, 5:08am UTC](https://discourse.threejs.org/t/obj-loader-and-materials/34976/2 "2022-02-17T05:08:24Z")

</div>

```javascript
loader.load(‘assets/tinker.obj’,function( object ){
const material = new THREE.MeshBasicMaterial({
color: 0xffff00
});
const mesh = object;
object.material=material;
object.scale.set(0.2,0.2,0.2);
scene.add( mesh );
},
function( xhr ){
console.log(( xhr.loaded / xhr.total * 100) + ‘% 100’);
},
function( error ){
console.log(‘An error happend’);
}
);

```

---

<div class="post-metadata">

**Author:** ![Jackson33](https://avatars.discourse-cdn.com/v4/letter/j/87869e/32.png) [@Jackson33](https://discourse.threejs.org/u/Jackson33)\
**Post date:** [February 17, 2022, 5:16am UTC](https://discourse.threejs.org/t/obj-loader-and-materials/34976/3 "2022-02-17T05:16:42Z")

</div>

I tried to use the code you posted and it still didn’t work. Do you know how you would do it from scratch?

---

<div class="post-metadata">

**Author:** ![Chaser\_Code](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/chaser_code/32/20199_2.png) [@Chaser\_Code](https://discourse.threejs.org/u/Chaser_Code)\
**Post date:** [February 17, 2022, 8:27am UTC](https://discourse.threejs.org/t/obj-loader-and-materials/34976/4 "2022-02-17T08:27:18Z")

</div>

Maybe there error in console. Can you upload full archive?

```javascript
loader.load(‘assets/tinker.obj’,function( object ){

const material = new THREE.MeshBasicMaterial({
color: 0xffff00
});

object.traverse( function ( child ) {
if ( child.isMesh ) child.material=material;
} );

object.scale.set(0.2,0.2,0.2);
scene.add( object );
},
function( xhr ){
console.log(( xhr.loaded / xhr.total * 100) + ‘% 100’);
},
function( error ){
console.log(‘An error happend’);
}
);

```
